How to use Generative AI to enhance your automation coding productivity
Tags: ansible, generativeai, iac, foundationmodels
Published: 2023-12-01 16:14:08

**Red Hat Ansible Lightspeed with IBM watsonx Code Assistant**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z1vczj8mhfv7ladn7oa6.png)
**What is IBM Watsonx?**

Watsonx is an AI and data platform with three core components and a set of AI assistants designed to help you scale and accelerate the impact of AI with trusted data across your business.

The core components of watsonx include a studio for new [foundation models](https://www.ibm.com/products/watsonx-ai/foundation-models), generative AI, and machine learning; a fit-for-purpose data store built on an open data lakehouse architecture; and a toolkit, to accelerate AI workflows that are built with responsibility, transparency, and explainability.
**What are the foundation models?**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/84a52jnj9jy26ww2ot3m.png)
Well, basically foundation models are the enterprise grade trustworthy large language models!

**What is Red Hat Ansible Lightspeed?**

‘Red Hat’ Ansible Lightspeed with IBM watsonx Code Assistant is a generative AI service engineered to help your automation teams create, adopt, and maintain Ansible content more efficiently. Connected to IBM watsonx Code Assistant, Red Hat Ansible Lightspeed helps you turn your automation ideas into Ansible code with natural language prompts.

As a ‘Red Hat’ Ansible Automation Platform component, Red Hat Ansible Lightspeed is accessed directly in Visual Studio Code via the Ansible extension.

So what are the features and what can you expect?

- **Task generation**: Generates a task for an Ansible Playbook or Role from a natural language prompt.
Multitask generation: Generates multiple Ansible task suggestions for Ansible Task files and Playbooks by providing a sequential chain of natural language task prompts chained together using ampersands (&) in YAML comment (#) lines.

- **Content source matching**: Attempts to match each generated code snipped recommendation to the top 3 closest potential data training sources, including the Ansible content, content authors, and content licenses.
- **Ansible code bot (technology preview mode as of publishing this article’s date)**: Scans existing content collections through selected Git repositories and automatically submits pull requests that can be qualitatively improved with the most up-to-date Ansible best practices.

- **Post-processing rules**: Augments generated code recommendations to ensure they adhere to Ansible best practices.

**So basically it generates content, enhances productivity, and democratizes automation.**

Okay, that’s nice, but how to use it?

**How to use ‘Red Hat Ansible Lightspeed with IBM watsonx Code Assistant’?**

Very simple, just follow the steps as provided hereafter.

- I assume you are using Microsoft Visual Studio Code either on MacOS or Windows.
- Install Red Hat’s ‘Ansible’ extension from the extensions library.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqgqh1aquglz6oo9atwb.png)

- Select the ‘Extension Settings’ gear.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uerbahj85d8jj8d16kca.png)

- Set the URL for Ansible Lightspeed (https://c.ai.ansible.redhat.com).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x24577edd94s36df2mnd.png)

- Open the above URL with your browser and log into the site either with a ‘Red Hat’ id or by using a GitHub ID.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/scmufwt0jdhbci0x2oep.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/htsbhrwkdscc1lneib15.png)

- Verify the status inside Visual Code by choosing the ‘Ansible’ in left side vertical toolbar.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ekdue3zf03t0d23k4vei.png)

- Yor are all set. Let’s try it.

Let’s say I begin with an Ansible YAML file such as the one below;

```
---
- name: Httpd podman
  hosts: all
  tasks: 
    # Assert ansible_user is not root & 
    # Install podman & 
    # Pull httpd container image & 
    # Create httpd container
```

And I want to achieve a result by the extension. I put the video which shows how it works.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2y0jhshmdlh349smzl8.gif)



Hereafter my output file;

```
---
- name: Httpd podman
  hosts: all
  tasks: 
    # Assert ansible_user is not root & 
    # Install podman & 
    # Pull httpd container image & 
    # Create httpd container
    - name: Assert ansible_user is not root
      ansible.builtin.fail:
        msg: '"ansible_user is not root"'
      when: not ansible_user == "root"
    
    - name: Install podman
      ansible.builtin.package:
        name: podman
        state: latest
    
    - name:  Pull httpd container image
      containers.podman.podman_image:
        name: docker.io/library/httpd
    
    - name: Create httpd container
      containers.podman.podman_container:
        name: testhttpd
        image: httpd
        state: started
        detach: true
        exposed_ports:
          - 80
        ports:
          - 8080:80
        volumes: /tmp/:/data
```

That’s all for today, thanks for reading this and stay tuned.