AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

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

  1. Open VS Code
  2. Search Extensions for "Ansible" (Red Hat)
  3. Install the Ansible extension
  4. Sign in to Ansible Lightspeed:
  5. Open Settings → Extensions → Ansible
  6. Enable Ansible Lightspeed
  7. Click Connect and authenticate with your Red Hat account

Configuration

// .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"
}

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

See also: Getting Started with Ansible Lightspeed Intelligent Assistant in AAP 2.6

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

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.

See also: Ansible Lightspeed AI Provider Compatibility: OpenAI, Azure, IBM Watsonx, and Gemini (BYOM Guide)

Lightspeed in AAP Web UI

AAP 2.5+ includes Lightspeed in the web-based playbook editor:

  1. Open a Job Template
  2. Click Edit Playbook
  3. Type a task name
  4. Lightspeed suggests completions inline
  5. Accept or modify the suggestion

Tips for Better Suggestions

  1. Be specific in task names — "Install nginx with SSL on Ubuntu 24.04" beats "Install web server"
  2. Set context first — Define hosts, vars, and become before writing tasks
  3. Use FQCN in your playbook — Lightspeed follows your style (fully qualified names)
  4. Iterate — Accept the suggestion, then refine by adding another descriptive task name
  5. 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 modules

Lightspeed vs GitHub Copilot for Ansible

FeatureAnsible LightspeedGitHub Copilot
Training dataAnsible-specific (watsonx)General code
FQCN awareness✅ NativePartial
Content attribution✅ Yes❌ No
Module parameter accuracyHighMedium
AAP integration✅ Web UI + VS CodeVS Code only
Enterprise licensingRed Hat subscriptionGitHub subscription

Best Practices

  1. Always review generated code — AI suggests, humans decide
  2. ansible-lint after generation — Validate generated tasks pass linting
  3. Test with Molecule — Generated roles should be tested like handwritten ones
  4. Use for learning — Great for understanding module parameters and best practices
  5. Start with task names — Write descriptive names, let Lightspeed fill in the YAML
  6. Provide context — The more context in your playbook, the better the suggestions

FAQ

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.

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home