Ansible Lightspeed with IBM watsonx Code Assistant: AI-Powered Automation Development
By Luca Berton · Published 2024-01-01 · Category: installation
Use Ansible Lightspeed with IBM watsonx Code Assistant for AI-powered playbook generation. Natural language to Ansible automation with enterprise-grade AI.
Introduction
Ansible Lightspeed with IBM watsonx Code Assistant brings AI-powered automation development to Ansible. Describe what you want in natural language, and Lightspeed generates syntactically correct, contextually aware Ansible tasks. It's integrated into VS Code and the AAP web UI, making it accessible to both experienced automators and newcomers.
See also: Elevating Ansible Development with Visual Studio Code
What is Ansible Lightspeed?
Ansible Lightspeed is an AI service that: • Generates Ansible tasks from natural language — Describe what you want in a task name, get working YAML • Understands context — Reads your existing playbook to generate consistent tasks • Trained on Ansible content — IBM watsonx model trained specifically on Ansible best practices • Enterprise-ready — Available in AAP 2.5+ with content source attribution
Setup in VS Code
Install the Extension
Open VS Code Search Extensions for "Ansible" (Red Hat) Install the Ansible extension Sign in to Ansible Lightspeed: • Open Settings → Extensions → Ansible • Enable Ansible Lightspeed • Click Connect and authenticate with your Red Hat accountConfiguration
// .vscode/settings.json
{
"ansible.lightspeed.enabled": true,
"ansible.lightspeed.suggestions.enabled": true,
"ansible.lightspeed.url": "https://c.ai.ansible.redhat.com",
"ansible.validation.lint.enabled": true,
"ansible.ansible.path": "/usr/bin/ansible"
}
See also: Getting Started with Ansible Lightspeed Intelligent Assistant in AAP 2.6
How It Works
Natural Language → Ansible Task
Write a descriptive task name, press Enter, and Lightspeed generates the task:
# You type the task name:
- name: Install nginx and ensure it's running on port 443
# Lightspeed generates:
- name: Install nginx and ensure it's running on port 443
block:
- name: Install nginx
ansible.builtin.package:
name: nginx
state: present
- name: Configure nginx for HTTPS
ansible.builtin.template:
src: nginx-ssl.conf.j2
dest: /etc/nginx/sites-enabled/default
notify: restart nginx
- name: Ensure nginx is running
ansible.builtin.service:
name: nginx
state: started
enabled: true
Context-Aware Suggestions
Lightspeed reads your existing playbook context:
---
- name: Deploy web application
hosts: webservers
become: true
vars:
app_version: "2.5.0"
app_port: 8080
tasks:
- name: Install Java 17
# Lightspeed knows: you're on webservers, have become, targeting Java
# Generates appropriate package installation for detected OS
- name: Download application WAR file
# Lightspeed uses app_version var from context
- name: Create systemd service for the application
# Lightspeed uses app_port var and Java context
Example Prompts and Results
Prompt: "Create a user with SSH key and sudo access"
- name: Create a user with SSH key and sudo access
block:
- name: Create user account
ansible.builtin.user:
name: "{{ username }}"
groups: sudo
append: true
shell: /bin/bash
create_home: true
state: present
- name: Set authorized SSH key
ansible.posix.authorized_key:
user: "{{ username }}"
key: "{{ user_ssh_public_key }}"
state: present
- name: Configure passwordless sudo
ansible.builtin.lineinfile:
path: /etc/sudoers.d/{{ username }}
line: "{{ username }} ALL=(ALL) NOPASSWD: ALL"
create: true
validate: visudo -cf %s
mode: '0440'
Prompt: "Configure PostgreSQL replication from primary to replica"
- name: Configure PostgreSQL replication from primary to replica
block:
- name: Configure primary for replication
ansible.builtin.lineinfile:
path: /etc/postgresql/16/main/postgresql.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^#?wal_level', line: 'wal_level = replica' }
- { regexp: '^#?max_wal_senders', line: 'max_wal_senders = 5' }
notify: restart postgresql
when: inventory_hostname == primary_host
- name: Create replication user
community.postgresql.postgresql_user:
name: replicator
password: "{{ vault_repl_password }}"
role_attr_flags: REPLICATION
become_user: postgres
when: inventory_hostname == primary_host
no_log: true
Prompt: "Backup MySQL database and upload to S3"
- name: Backup MySQL database and upload to S3
block:
- name: Create MySQL backup
community.mysql.mysql_db:
state: dump
name: "{{ db_name }}"
target: "/tmp/{{ db_name }}-{{ ansible_date_time.date }}.sql.gz"
no_log: true
- name: Upload backup to S3
amazon.aws.s3_object:
bucket: "{{ backup_bucket }}"
object: "mysql/{{ db_name }}-{{ ansible_date_time.date }}.sql.gz"
src: "/tmp/{{ db_name }}-{{ ansible_date_time.date }}.sql.gz"
mode: put
encryption: aws:kms
- name: Clean up local backup
ansible.builtin.file:
path: "/tmp/{{ db_name }}-{{ ansible_date_time.date }}.sql.gz"
state: absent
See also: Ansible Lightspeed AI Provider Compatibility: OpenAI, Azure, IBM Watsonx, and Gemini (BYOM Guide)
Content Source Attribution
Lightspeed provides transparency about its training data:
# After generating a suggestion, you may see:
# Source: ansible.builtin collection documentation
# Source: community.general 10.0.0 examples
# Source: Red Hat certified content
This helps enterprises verify that generated code comes from trusted, licensed sources.
Lightspeed in AAP Web UI
AAP 2.5+ includes Lightspeed in the web-based playbook editor: Open a Job Template Click Edit Playbook Type a task name Lightspeed suggests completions inline Accept or modify the suggestion
Tips for Better Suggestions
Be specific in task names — "Install nginx with SSL on Ubuntu 24.04" beats "Install web server" Set context first — Definehosts, vars, and become before writing tasks
Use FQCN in your playbook — Lightspeed follows your style (fully qualified names)
Iterate — Accept the suggestion, then refine by adding another descriptive task name
Include variable names — "Deploy {{ app_name }} version {{ app_version }}" gives context
Limitations
• Review all suggestions — AI-generated code must be reviewed by a human • No secrets handling — Lightspeed won't generate vault-encrypted content • Internet required — Suggestions require connectivity to the Lightspeed service • Ansible-specific — Only generates Ansible YAML, not general Python/Bash • Training data cutoff — May not know about the very latest collection modulesLightspeed vs GitHub Copilot for Ansible
| Feature | Ansible Lightspeed | GitHub Copilot | |---------|-------------------|---------------| | Training data | Ansible-specific (watsonx) | General code | | FQCN awareness | ✅ Native | Partial | | Content attribution | ✅ Yes | ❌ No | | Module parameter accuracy | High | Medium | | AAP integration | ✅ Web UI + VS Code | VS Code only | | Enterprise licensing | Red Hat subscription | GitHub subscription |
Best Practices
Always review generated code — AI suggests, humans decide ansible-lint after generation — Validate generated tasks pass linting Test with Molecule — Generated roles should be tested like handwritten ones Use for learning — Great for understanding module parameters and best practices Start with task names — Write descriptive names, let Lightspeed fill in the YAML Provide context — The more context in your playbook, the better the suggestionsFAQ
Is Lightspeed free?
The basic VS Code experience is free with a Red Hat account. Enterprise features (content attribution, telemetry, AAP integration) require an AAP subscription.
Does it send my playbooks to the cloud?
Lightspeed sends the current task context (task name + surrounding YAML) to IBM watsonx for inference. It does not store your playbooks. Enterprise deployments can use on-premises watsonx.
Can it generate entire playbooks?
Currently best at individual tasks and small blocks. For full playbooks, write the structure (hosts, vars) yourself and let Lightspeed generate each task.
Conclusion
Ansible Lightspeed with IBM watsonx Code Assistant accelerates automation development by translating natural language into working Ansible tasks. Whether you're an experienced automator looking to work faster or a newcomer learning Ansible, AI-assisted development makes automation more accessible and productive.
Related Articles
• Ansible Automation Platform 2.6 • Ansible for Beginners • Ansible Execution EnvironmentsCategory: installation