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-coreinstalled - 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.ansibleOr search “Ansible” in the VS Code Extensions marketplace and install the one from Red Hat.
Enable Lightspeed
- Open VS Code Settings (
Ctrl+,) - Search for “Ansible Lightspeed”
- Enable Ansible > Lightspeed: Enabled
- Set Ansible > Lightspeed: URL to:
- Community:
https://c.ai.ansible.redhat.com - Enterprise: your Ansible Automation Platform URL
- Community:
Authenticate
- Click the Ansible Lightspeed icon in the VS Code status bar
- Select “Connect” — opens Red Hat SSO in browser
- Authorize the application
- 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 packagePress Tab or wait for the suggestion. Lightspeed generates:
- name: Install nginx package
ansible.builtin.dnf:
name: nginx
state: presentKey things to notice:
- FQCN used —
ansible.builtin.dnfnot justdnf - Correct module for RHEL —
dnfnotapt - Idempotent —
state: presentnot 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: restartedStep 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 patternsSpecify 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: 10Step 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: trueStep 5: Use Lightspeed for Troubleshooting
When a playbook fails, Lightspeed can help fix it:
- Select the failing task
- Right-click → “Ansible Lightspeed: Explain this”
- 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
whenconditions — 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
| Feature | Ansible Lightspeed | GitHub Copilot |
|---|---|---|
| Ansible-specific training | Yes (Ansible Galaxy + docs) | General code |
| FQCN usage | Always | Sometimes |
| Module accuracy | High | Medium |
| RHEL patterns | Excellent | Good |
| Content attribution | Yes (enterprise) | No |
| Price | Free (community) / included in AAP | $10-19/mo |
| On-prem | Yes (enterprise) | Yes (enterprise) |
For a broader comparison, see my Ansible Lightspeed AI automation guide.
Related Resources
- Ansible Lightspeed AI automation 2026
- Ansible tutorial for beginners
- Ansible playbook examples
- Red Hat Ansible Automation Platform
- Ansible cheat sheet
- AI-generated Ansible playbooks: best practices
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.

