How to use Generative AI to enhance your automation coding productivity

aairom

Alain Airom

Posted on December 1, 2023

How to use Generative AI to enhance your automation coding productivity

Red Hat Ansible Lightspeed with IBM watsonx Code Assistant

Image description
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, 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
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

  • Select the ‘Extension Settings’ gear.

Image description

Image description

  • 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

Image description

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

Image description

  • 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
Enter fullscreen mode Exit fullscreen mode

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

Image description

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
Enter fullscreen mode Exit fullscreen mode

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

💖 💪 🙅 🚩
aairom
Alain Airom

Posted on December 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related