Skip to main content
🎓 Claude Code Masterclass Learn AI-assisted development on Udemy — plus the companion book on Leanpub & Amazon. Start Learning
Ansible Lightspeed Tutorial: Getting Started
Automation

Ansible Lightspeed Tutorial

Step-by-step Ansible Lightspeed tutorial. Install, configure, and generate your first AI-powered playbooks with IBM watsonx Code Assistant.

LB
Luca Berton
· 3 min read

Ansible Lightspeed with IBM watsonx Code Assistant is the most practical AI coding tool I have used. Unlike general-purpose copilots that generate mediocre Ansible, Lightspeed was trained specifically on Ansible content and understands modules, FQCNs, and role structure. Here is how to set it up and use it effectively.

What Is Ansible Lightspeed?

Ansible Lightspeed is an AI-powered content generation service built into the Ansible VS Code extension. It uses IBM watsonx foundation models (trained on Ansible Galaxy, documentation, and best practices) to generate:

  • Task suggestions from natural language comments
  • Complete playbooks from descriptions
  • Role structures with proper variable handling
  • Error fixes for broken YAML

It is available in two tiers:

  • Community — free, basic suggestions via Red Hat account
  • Enterprise — IBM watsonx Code Assistant for Red Hat Ansible Automation Platform, with custom model tuning and content source attribution

Prerequisites

  • VS Code 1.85+
  • Ansible extension for VS Code (redhat.ansible)
  • Red Hat account (free at developers.redhat.com)
  • Python 3.10+ with ansible-core installed
  • For enterprise: Ansible Automation Platform 2.4+ subscription

Step 1: Install and Configure

Install the Extension

# Install via VS Code CLI
code --install-extension redhat.ansible

Or search “Ansible” in the VS Code Extensions marketplace and install the one from Red Hat.

Enable Lightspeed

  1. Open VS Code Settings (Ctrl+,)
  2. Search for “Ansible Lightspeed”
  3. Enable Ansible > Lightspeed: Enabled
  4. Set Ansible > Lightspeed: URL to:
    • Community: https://c.ai.ansible.redhat.com
    • Enterprise: your Ansible Automation Platform URL

Authenticate

  1. Click the Ansible Lightspeed icon in the VS Code status bar
  2. Select “Connect” — opens Red Hat SSO in browser
  3. Authorize the application
  4. Return to VS Code — status bar shows “Lightspeed Connected”

Step 2: Generate Your First Playbook

The key to good results: write descriptive task names as comments.

Basic Pattern

Create a new .yml file and type a task name:

---
- name: Deploy and configure Nginx web server on RHEL 9
  hosts: webservers
  become: true

  tasks:
    # Install nginx package

Press Tab or wait for the suggestion. Lightspeed generates:

    - name: Install nginx package
      ansible.builtin.dnf:
        name: nginx
        state: present

Key things to notice:

  • FQCN usedansible.builtin.dnf not just dnf
  • Correct module for RHELdnf not apt
  • Idempotentstate: present not a raw command

Multi-Task Generation

Write multiple comments and let Lightspeed fill in each:

  tasks:
    # Install nginx package
    - name: Install nginx package
      ansible.builtin.dnf:
        name: nginx
        state: present

    # Copy custom nginx configuration from template
    - name: Copy custom nginx configuration from template
      ansible.builtin.template:
        src: nginx.conf.j2
        dest: /etc/nginx/nginx.conf
        mode: "0644"
        validate: nginx -t -c %s
      notify: Restart nginx

    # Ensure nginx service is running and enabled
    - name: Ensure nginx service is running and enabled
      ansible.builtin.systemd:
        name: nginx
        state: started
        enabled: true

    # Open firewall ports for HTTP and HTTPS
    - name: Open firewall ports for HTTP and HTTPS
      ansible.posix.firewalld:
        service: "{{ item }}"
        permanent: true
        state: enabled
        immediate: true
      loop:
        - http
        - https

  handlers:
    # Restart nginx service
    - name: Restart nginx
      ansible.builtin.systemd:
        name: nginx
        state: restarted

Step 3: Prompting Techniques for Better Output

Be Specific About the Target OS

# Bad: "Install docker"
# Good: "Install Docker CE from official repo on RHEL 9 using dnf"

Mention Module Names in Comments

# "Use ansible.posix.firewalld to open port 8080"
# Better than: "open port 8080"

Include Variable References

# "Create user {{ app_user }} with home directory {{ app_home }}"
# Lightspeed picks up variable patterns

Specify Error Handling

# "Install package with retries using until loop, 3 attempts, 10 second delay"
- name: Install package with retries
  ansible.builtin.dnf:
    name: "{{ package_name }}"
    state: present
  register: install_result
  until: install_result is success
  retries: 3
  delay: 10

Step 4: Generate Roles

Lightspeed excels at generating role structures:

# Create a role for PostgreSQL 15 installation and configuration on RHEL 9
# Include: package installation, initialization, custom pg_hba.conf,
# service management, and firewall configuration

# roles/postgresql/tasks/main.yml
---
- name: Install PostgreSQL 15 packages
  ansible.builtin.dnf:
    name:
      - postgresql-server
      - postgresql-contrib
      - python3-psycopg2
    state: present

- name: Initialize PostgreSQL database
  ansible.builtin.command:
    cmd: postgresql-setup --initdb
    creates: /var/lib/pgsql/data/PG_VERSION

- name: Deploy pg_hba.conf
  ansible.builtin.template:
    src: pg_hba.conf.j2
    dest: /var/lib/pgsql/data/pg_hba.conf
    owner: postgres
    group: postgres
    mode: "0600"
  notify: Restart postgresql

- name: Ensure PostgreSQL is running
  ansible.builtin.systemd:
    name: postgresql
    state: started
    enabled: true

- name: Open PostgreSQL port
  ansible.posix.firewalld:
    port: 5432/tcp
    permanent: true
    state: enabled
    immediate: true

Step 5: Use Lightspeed for Troubleshooting

When a playbook fails, Lightspeed can help fix it:

  1. Select the failing task
  2. Right-click → “Ansible Lightspeed: Explain this”
  3. Review the explanation and suggested fix

Or write a comment describing the fix:

# Fix: the previous copy task fails because the dest directory
# does not exist yet. Create it first with correct permissions.
- name: Create application directory
  ansible.builtin.file:
    path: /opt/myapp
    state: directory
    mode: "0755"
    owner: "{{ app_user }}"

Tips from Production Use

After using Lightspeed across dozens of enterprise projects, here is what I have learned:

What it does well:

  • Standard infrastructure tasks (package install, service management, firewall)
  • RHEL-specific patterns (dnf, systemd, firewalld, SELinux)
  • Generating boilerplate with correct FQCN
  • Role structure and handler patterns

Where you need to review carefully:

  • Complex when conditions — sometimes generates overly simple logic
  • Jinja2 filters in templates — can hallucinate filter names
  • Multi-platform playbooks — tends to assume one OS family
  • Security-sensitive tasks — always review crypto, auth, and permission settings

Best practice: Use Lightspeed for the first draft, then review and refine. It saves 60-70% of typing time on typical infrastructure playbooks.

Enterprise Features (watsonx Code Assistant)

The enterprise version adds:

  • Content source matching — shows which Ansible Galaxy content inspired the suggestion
  • Custom model tuning — train on your organization’s playbooks
  • Post-processing rules — enforce naming conventions, banned modules, required tags
  • Audit trail — log all AI-generated suggestions and acceptances
  • On-premises deployment — run the model inside your network

Lightspeed vs GitHub Copilot for Ansible

FeatureAnsible LightspeedGitHub Copilot
Ansible-specific trainingYes (Ansible Galaxy + docs)General code
FQCN usageAlwaysSometimes
Module accuracyHighMedium
RHEL patternsExcellentGood
Content attributionYes (enterprise)No
PriceFree (community) / included in AAP$10-19/mo
On-premYes (enterprise)Yes (enterprise)

For a broader comparison, see my Ansible Lightspeed AI automation guide.

About the Author

I am Luca Berton, AI and Cloud Advisor and author of multiple Ansible books including Ansible for VMware by Examples and Ansible for Kubernetes by Example. Book a consultation to discuss AI-powered automation for your team.

Free 30-min AI & Cloud consultation

Book Now