watsonx Code Assistant for Red Hat Ansible Lightspeed

 View Only

Ansible Automation with Generative AI

By Sarath Chandra Vidya Sagar Machupalli posted Sun November 26, 2023 03:10 PM

  

Today, we are living in the world of artificial intelligence (AI). With Generative AI, writing code has become simpler. Coding is not about linting, formatting, and debugging anymore.

In this article, you will learn about how Ansible is bringing AI tools to your Integrated Development Environment to make your automation coding experience simpler, smoother, and more efficient.

What is Ansible?

Simply put, Ansible built is a simple IT automation tool that helps you in provisioning infrastructure, install software, and supports application automation through advanced workflows.

Ansible automation can be used to automate daily tasks, improve security and compliance, patch systems, and share automation across your entire organization. Ansible allows you to automate z/OS applications and IT infrastructure as part of your enterprise automation strategy using a proven and consistent approach.

Ansible + AI

Ansible Lightspeed with IBM Watsonx Code Assistant, a new generative AI service for Ansible automation, was announced at Red Hat Summit and AnsibleFest 2023. Ansible Lightspeed with IBM Watsonx Code Assistant helps you to create Ansible code more efficiently. The tool that is available as a Visual Code Extension reads plain English entered by the developer, and then it interacts with IBM watsonx foundation models to generate code recommendations for automation tasks that are then used to create Ansible Playbooks.

Ansible Lightspeed with IBM Watson Code Assistant in action

How to Setup and Getting Started

  1. Install the Ansible VSCode extension by Red Hat
  2. Follow the instructions documented here to configure the extension to enable Ansible Lightspeed.
  3. Once successfully installed and configured, you should see a tab at the bottom, as shown in the image below
Ansible Lightspeed training matches

Write the Name of the Task To Generate Ansible

  1. Create a new Ansible playbook called ping.yml.
  2. Add a new Ansible task with a name in plain English, like “Test ping with a register” or “HTTP PUT request to create a new object”
  3. You should see an Ansible module recommendation. Hit Tab, and the code will be inserted. You can further build on the Ansible code that is generated.

For Ansible yaml code snippets, check my code repository — https://github.com/VidyasagarMSC/ansible-yaml-snippets

Sample Ping Ansible Code

---
- name: Ping test
hosts: machines
gather_facts: false
tasks:
- name: Test ping
ansible.builtin.ping:
register: ping_result
- name: Print register information from the previous task
ansible.builtin.debug:
var: ping_result

HTTP PUT Ansible Task Generated Using Ansible Lightspeed

- name: HTTP PUT request with JSON object
ansible.builtin.uri:
url: "{{ url }}"
method: PUT
body: "{{ body }}"
headers:
Accept: application/json
Authorization: Bearer {{ token_permission }}
validate_certs: false
register: result
changed_when: false
become: true
Red Hat Ansible Lightspeed with IBM watsonx Code Assistant is now generally available (GA)

What’s Next

Explore Ansible Lightspeed, and if you have any queries, feel free to contact me on Twitter or LinkedIn. Don’t forget to star my Ansible yaml snippets repository on GitHub.

0 comments
44 views

Permalink