Code Generation for Ansible
Get started
A recolored leadspace using the Watson for Customer Care leadspace as its basis.
Code Generation for Ansible

IBM watsonx Code Assistant (WCA) for Red Hat Ansible Lightspeed (RHAL) demystifies the process of Ansible playbook creation through generative AI-powered content recommendations. Purpose-built to accelerate IT Automation, WCA for RHAL delivers content recommendations that adhere to leading practices, reducing errors and improving the consistency of Ansible tasks, roles, and playbooks. WCA for RHAL can also generate content using natural language requests written in plain English text, helping to scale and expand access to automation within the enterprise.

WCA for RHAL uses an IBM Granite large language model (LLM) that is trained on expansive datasets of Ansible playbooks. The LLM can be tuned using an enterprise’s own data to understand the nuances of its automation syntax and structure. Users can accept suggestions as-is or improve the content recommendations to their exact needs, further decreasing time-to-value for automation and accelerating development cycles through AI-generated content recommendations.


Solution Overview

WCA for RHAL is comprised of the following components (shown in the diagram above):

  1. An Ansible Playbook contains the code needed to run automation on managed nodes and endpoints, e.g., servers, containers, network devices, and cloud services.


  2. The Playbook Source Code Management (SCM) is where all production and development branches of the Ansible playbooks are maintained. While there are many SCM solutions available, solutions based on Git are the most commonly used and are thus assumed in the discussion that follows.


  3. The Ansible Automation Platform from Red Hat includes the Ansible core engine, linting service, deployment management services, and user interface for running and troubleshooting Ansible playbooks. Typically, it is configured to pull updated playbooks from SCM on a per-merge basis.


  4. Red Hat Ansible Lightspeed is an IBM application that reads natural language prompts and code context and sends it to the IBM watsonx Code Assistant service for foundation model matching. It generates content and match audit information that it sends back to VS Code.


  5. IBM watsonx Code Assistant Service (WCA for RHAL) is an IBM application that receives prompt requests from Red Hat Ansible Lightspeed and performs matching against a Large Language Model (LLM). WCA for RHAL can also train the LLM with additional Ansible playbook datasets. IBM watsonx Code Assistant and Red Hat Ansible Lightspeed work together to provide complete and accurate content generation proposals that follow leading practices.


  6. Code Large Language Model (LLM) is a foundation model for content generation that is based on IBM's Granite model for Ansible. It may also be trained to include additional playbook code generated by vendors or by enterprise users.


    Usage and Walkthrough

The diagram above illustrates how the components of WCA for RHAL work together to reduce the time and improve the consistency of Ansible playbooks.

  1. A developer pulls the latest Ansible Playbook code from a code repository on the Playbook SCM and opens it in VS Code.
  2. The developer adds an Ansible task in the form of a natural language prompt, e.g., - name: Install httpd.conf using a template.
  3. The Ansible Extension for VS Code sends a Lightspeed request to the IBM watsonx Code Assistant Service.
  4. IBM watsonx Code Assistant generates a response to the natural language prompt. The response is based on the contents of its LLM as well as all context it can glean from any other existing code, variables, and other information in the file.
  5. IBM watsonx Code Assistant sends the response to the natural language prompt in the form of Ansible code (YAML). An example of the generated content appears below. ansible.builtin.template:
      src: httpd.conf.j2
      dest: /etc/httpd/conf/httpd.conf
      mode: "0644"
      owner: root
      group: root
  6. The developer accepts and/or modifies the AI-generated content proposal, commits the change, and pushes the commit to the repository on the Playbook SCM.
  7. An Ansible Project configured on Red Hat Ansible Automation Platform detects the update on the Playbook SCM, downloads the updated code, and runs the updated playbook on the indicated endpoints.


  • Microsoft Visual Studio Code for MacOS or Linux
  • python3
  • ansible, ansible-lint
  • Ansible Extension for VS Code
  • Red Hat Ansible Automation Platform
  • or Account
  • Connection to IBM watsonx Code Assistant
  • Microsoft Visual Studio Code for Windows
  • Windows Services for Linux (WSL) version 2
  • Fedora 37, CentOS, or RHEL 8 Container Base for WSL
  • python3, ansible, and ansible-lint as above
Unique Features of IBM watsonx Code Assistant
  • Code Generation: Simplifies the process of generating Ansible playbooks by using natural language inputs in the Ansible task description.
  • Coding Standards Enforcement: Enables training of Ansible content that follows leading public and enterprise practices, which in turn generates code that follow said standards.
  • Productivity Enhancement: Integrates AI-generated code recommendations directly into the integrated development environment (IDE).
Next steps

Talk to our experts about implementing a hybrid cloud deployment pattern.

More ways to explore Hybrid Cloud Architecture Center Diagram tools and templates IBM Well-Architected Framework

Al Hamid, Mihai Criveti, Chris Kirby, Pete Nuwayser

Updated: December 5, 2023