| name | ansible-interactive |
| description | Interactive step-by-step guided Ansible development workflow from environment setup through playbook deployment. Use this skill when the user asks to: "guide me through ansible", "interactive ansible setup", "step by step ansible", "walk me through ansible development", "help me start with ansible", "ansible project setup", or wants hands-on guided assistance with Ansible development. Always invoke this skill for interactive, beginner-friendly Ansible workflows.
|
| version | 1.0.0 |
| allowed-tools | ["Write","Read","Bash","Glob"] |
Ansible Interactive Development Skill
Provide step-by-step guided Ansible development workflow, from initial environment setup through playbook deployment. This skill offers interactive assistance at every stage with validation and troubleshooting.
What is Interactive Ansible Development?
Interactive development breaks complex Ansible projects into manageable steps with immediate feedback and validation at each stage.
Key Benefits:
- Guided workflow - Step-by-step progression with clear objectives
- Immediate validation - Test each step before moving forward
- Error prevention - Catch issues early in the development process
- Learning-focused - Understand concepts while building
- Production-ready - Follow Red Hat CoP standards throughout
Who is this for?
- Ansible beginners starting their first project
- Teams transitioning to Ansible from shell scripts
- Developers wanting guided best practices
- Anyone preferring incremental, validated development
Interactive Development Workflow
Phase 1: Environment Analysis
Objective: Understand current environment and requirements
Steps:
-
Assess Current State
ansible --version
python3 --version
ssh -V
-
Define Requirements
- What systems will you manage? (servers, network devices, cloud)
- What tasks need automation? (deployment, configuration, patching)
- What's the target environment? (development, staging, production)
- How many hosts? (affects inventory structure)
- What credentials are needed? (SSH keys, passwords, API tokens)
-
Validate Prerequisites
ping -c 3 target-host
ssh user@target-host "echo 'Connection successful'"
ssh user@target-host "sudo -n true && echo 'Passwordless sudo configured'"
Interactive Questions:
- "What are you trying to automate?"
- "How many hosts will you manage?"
- "Do you have SSH access to all target systems?"
- "Are you managing Linux, Windows, or network devices?"
Validation: All prerequisites met before proceeding.
Phase 2: Project Initialization
Objective: Create well-structured Ansible project following Red Hat CoP
Steps:
-
Create Project Structure
mkdir -p my-ansible-project
cd my-ansible-project
mkdir -p {inventory,group_vars,host_vars,roles,playbooks,files,templates}
touch ansible.cfg
git init
-
Configure ansible.cfg
[defaults]
inventory = inventory/hosts.yml
roles_path = roles
host_key_checking = False
retry_files_enabled = False
stdout_callback = yaml
callbacks_enabled = ansible.posix.profile_tasks
interpreter_python = auto_silent
[privilege_escalation]
become = False
become_method = sudo
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
-
Create Initial Inventory
---
all:
children:
development:
hosts:
dev-server-01:
ansible_host: 192.168.1.10
ansible_user: ansible
production:
hosts:
prod-server-01:
ansible_host: 192.168.1.20
ansible_user: ansible
Interactive Questions:
- "What's your project name?"
- "Which hosts belong to which groups?"
- "What connection method will you use (SSH, WinRM, local)?"
Validation:
tree -L 2
ansible-config dump --only-changed
ansible-inventory --list -i inventory/hosts.yml
Phase 3: Connectivity Testing
Objective: Verify Ansible can connect to all managed hosts
Steps:
-
Test Basic Connectivity
ansible all -m ping
-
Gather Facts
ansible all -m setup
ansible all -m setup -a "filter=ansible_distribution*"
-
Test Privilege Escalation
ansible all -m shell -a "whoami" --become
-
Validate Connectivity Report
ansible all -m setup --tree /tmp/facts
cat /tmp/facts/dev-server-01
Interactive Troubleshooting:
Issue: Connection refused
ping target-host
nmap -p 22 target-host
ssh -vvv user@target-host
Issue: Authentication failed
ssh-add -l
ssh -i ~/.ssh/id_rsa user@target-host
ssh user@target-host "cat ~/.ssh/authorized_keys"
Issue: Sudo password required
all:
vars:
ansible_become_password: "{{ lookup('env', 'ANSIBLE_BECOME_PASSWORD') }}"
Validation: All hosts respond successfully to ansible all -m ping
Phase 4: First Playbook (Simple Task)
Objective: Create and run a simple playbook to validate workflow
Steps:
-
Create Simple Playbook
---
- name: Test connectivity and gather information
hosts: all
gather_facts: yes
tasks:
- name: Display hostname
ansible.builtin.debug:
msg: "Hostname: {{ ansible_hostname }}"
- name: Display OS distribution
ansible.builtin.debug:
msg: "OS: {{ ansible_distribution }} {{ ansible_distribution_version }}"
- name: Check uptime
ansible.builtin.command: uptime
register: uptime_result
changed_when: false
- name: Display uptime
ansible.builtin.debug:
msg: "{{ uptime_result.stdout }}"
-
Validate Syntax
ansible-playbook playbooks/test_connectivity.yml --syntax-check
-
Run in Check Mode
ansible-playbook playbooks/test_connectivity.yml --check
-
Execute Playbook
ansible-playbook playbooks/test_connectivity.yml
-
Review Output
- All tasks completed successfully?
- Any warnings or deprecation notices?
- All hosts responded?
Interactive Questions:
- "Did all tasks complete successfully?"
- "Do you see any warnings that need addressing?"
- "Are the gathered facts what you expected?"
Validation: Playbook runs without errors on all hosts.
Phase 5: Incremental Feature Addition
Objective: Add features incrementally with validation at each step
Example: Package Installation
-
Single Task Playbook
---
- name: Install package
hosts: development
become: yes
tasks:
- name: Install vim
ansible.builtin.package:
name: vim
state: present
-
Test and Validate
ansible-playbook playbooks/install_package.yml --check
ansible-playbook playbooks/install_package.yml --limit development
ansible development -m shell -a "which vim"
-
Add Idempotency Test
ansible-playbook playbooks/install_package.yml
ansible-playbook playbooks/install_package.yml
-
Expand with Variables
---
- name: Install package
hosts: development
become: yes
vars:
packages_to_install:
- vim
- git
- curl
tasks:
- name: Install packages
ansible.builtin.package:
name: "{{ item }}"
state: present
loop: "{{ packages_to_install }}"
-
Move Variables to Group Vars
---
packages_to_install:
- vim
- git
- curl
- htop
---
packages_to_install:
- vim
- git
Interactive Questions:
- "What package do you need to install?"
- "Should this apply to all hosts or specific groups?"
- "Do different environments need different packages?"
Validation: Package installed, idempotency verified, variables externalized.
Phase 6: Configuration Management
Objective: Manage configuration files with templates
Steps:
-
Create Configuration Template
{# templates/nginx.conf.j2 #}
user {{ nginx_user }};
worker_processes {{ nginx_worker_processes }};
events {
worker_connections {{ nginx_worker_connections }};
}
http {
server {
listen {{ nginx_port }};
server_name {{ ansible_hostname }};
location / {
root {{ nginx_document_root }};
}
}
}
-
Define Variables
---
nginx_user: nginx
nginx_worker_processes: auto
nginx_worker_connections: 1024
nginx_port: 80
nginx_document_root: /var/www/html
-
Create Playbook
---
- name: Configure Nginx
hosts: web_servers
become: yes
tasks:
- name: Deploy Nginx configuration
ansible.builtin.template:
src: templates/nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: '0644'
validate: nginx -t -c %s
notify: Reload nginx
handlers:
- name: Reload nginx
ansible.builtin.service:
name: nginx
state: reloaded
-
Test Configuration
ansible-playbook playbooks/configure_nginx.yml --check --diff
ansible-playbook playbooks/configure_nginx.yml
Interactive Questions:
- "What configuration file needs management?"
- "What values should be configurable?"
- "Do different environments need different settings?"
Validation: Configuration deployed, syntax validated, service reloaded.
Phase 7: Role Development
Objective: Convert playbook tasks into reusable roles
Steps:
-
Create Role Structure
ansible-galaxy role init roles/nginx_install
-
Move Tasks to Role
---
- name: Install Nginx
ansible.builtin.package:
name: nginx
state: present
- name: Deploy configuration
ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
validate: nginx -t -c %s
notify: Reload nginx
- name: Ensure Nginx is running
ansible.builtin.service:
name: nginx
state: started
enabled: yes
-
Move Variables to Defaults
---
nginx_install_user: nginx
nginx_install_worker_processes: auto
nginx_install_port: 80
-
Move Template to Role
mv templates/nginx.conf.j2 roles/nginx_install/templates/
-
Create Type Playbook
---
- name: Configure web server type
hosts: web_servers
become: yes
roles:
- role: nginx_install
tags: ['nginx', 'web']
-
Test Role
ansible-playbook playbooks/web_server.yml
ansible-playbook playbooks/web_server.yml --tags nginx
Interactive Questions:
- "What functionality should this role provide?"
- "What should be configurable vs. hardcoded?"
- "Will this role be reused across projects?"
Validation: Role structure correct, playbook uses role, all tests pass.
Phase 8: Testing and Validation
Objective: Implement testing for reliability
Steps:
-
Install Testing Tools
pip install ansible-lint molecule molecule-plugins[podman]
-
Lint Playbooks
ansible-lint playbooks/web_server.yml
-
Initialize Molecule
cd roles/nginx_install
molecule init scenario
-
Run Molecule Tests
molecule test
molecule create
molecule converge
molecule verify
molecule destroy
-
Test Idempotency
molecule test
ansible-playbook playbooks/web_server.yml
ansible-playbook playbooks/web_server.yml | grep -q 'changed=0' && echo "Idempotent"
Interactive Questions:
- "Did ansible-lint report any issues?"
- "Are you seeing any failed tests?"
- "Is the role idempotent?"
Validation: All lint checks pass, Molecule tests succeed, idempotency verified.
Phase 9: Documentation
Objective: Document project for team collaboration
Steps:
-
Create Project README
# My Ansible Project
## Overview
This project manages our web server infrastructure.
## Prerequisites
- Ansible 2.9+
- SSH access to target hosts
- Sudo privileges on managed hosts
## Inventory
- `development` - Development servers
- `production` - Production servers
## Playbooks
- `web_server.yml` - Configure web servers with Nginx
## Usage
```bash
# Deploy to development
ansible-playbook playbooks/web_server.yml --limit development
# Deploy to production
ansible-playbook playbooks/web_server.yml --limit production
Roles
nginx_install - Install and configure Nginx web server
-
Document Roles
# roles/nginx_install/README.md
# Nginx Install Role
Installs and configures Nginx web server.
## Requirements
None
## Role Variables
- `nginx_install_port` - Listen port (default: 80)
- `nginx_install_user` - Nginx user (default: nginx)
## Example Playbook
```yaml
- hosts: web_servers
roles:
- role: nginx_install
nginx_install_port: 8080
-
Add Inline Comments
tasks:
- name: Install Nginx
ansible.builtin.package:
name: nginx
state: present
Validation: README exists, roles documented, usage examples provided.
Phase 10: Production Deployment
Objective: Deploy to production safely
Steps:
-
Pre-Deployment Checklist
ansible-lint playbooks/*.yml
molecule test
ansible-inventory --list --yaml -i inventory/hosts.yml
ansible production --list-hosts
-
Deploy to Staging First
ansible-playbook playbooks/web_server.yml --limit staging
ansible staging -m uri -a "url=http://localhost return_content=yes"
-
Production Deployment
ansible-playbook playbooks/web_server.yml --limit production --check --diff
ansible-playbook playbooks/web_server.yml --limit production
-
Post-Deployment Validation
ansible production -m service_facts
ansible production -m uri -a "url=http://localhost/health"
ansible production -m shell -a "tail -20 /var/log/nginx/error.log"
-
Rollback Plan
---
- name: Rollback Nginx to previous version
hosts: "{{ target_hosts }}"
become: yes
tasks:
- name: Stop Nginx
ansible.builtin.service:
name: nginx
state: stopped
- name: Restore previous configuration
ansible.builtin.copy:
src: /etc/nginx/nginx.conf.bak
dest: /etc/nginx/nginx.conf
remote_src: yes
- name: Start Nginx
ansible.builtin.service:
name: nginx
state: started
Interactive Questions:
- "Have you verified the changes in staging?"
- "Do you have a rollback plan?"
- "Is this deployment during a maintenance window?"
Validation: Successful production deployment with verification.
Interactive Workflow Patterns
Pattern 1: Build-Test-Deploy Loop
vim roles/myapp/tasks/main.yml
ansible-playbook playbooks/myapp.yml --syntax-check
ansible-lint playbooks/myapp.yml
ansible-playbook playbooks/myapp.yml --check --limit dev
ansible-playbook playbooks/myapp.yml --limit dev
ansible dev -m shell -a "systemctl status myapp"
Pattern 2: Incremental Host Rollout
---
- name: Rolling update with validation
hosts: web_servers
serial: 1
tasks:
- name: Remove from load balancer
- name: Update application
- name: Verify health
ansible.builtin.uri:
url: http://localhost/health
status_code: 200
retries: 5
delay: 10
- name: Add back to load balancer
Pattern 3: Progressive Environment Deployment
ansible-playbook playbooks/deploy.yml --limit development
ansible-playbook playbooks/deploy.yml --limit staging
ansible-playbook playbooks/deploy.yml --limit "production[0]"
ansible-playbook playbooks/deploy.yml --limit production
Interactive Troubleshooting Guide
When Playbooks Fail
Step 1: Identify the failure
ansible-playbook playbooks/site.yml -vvv
Step 2: Isolate the problem
ansible-playbook playbooks/site.yml --tags problem_task
ansible-playbook playbooks/site.yml --limit problem_host
Step 3: Debug interactively
- name: Debug variable
ansible.builtin.debug:
var: my_variable
verbosity: 0
- name: Debug registered result
ansible.builtin.debug:
msg: "{{ result | to_nice_json }}"
Step 4: Test manually
ansible problem_host -m shell -a "the-failing-command"
ansible problem_host -m stat -a "path=/path/to/file"
Step 5: Fix and verify
ansible-playbook playbooks/site.yml --check
ansible-playbook playbooks/site.yml
Best Practices for Interactive Development
1. Always Validate Each Step
ansible-playbook playbook.yml --syntax-check
ansible-lint playbook.yml
ansible-playbook playbook.yml --check
ansible-playbook playbook.yml
2. Use Version Control
git add .
git commit -m "Phase 3: Connectivity testing complete"
git push
3. Test on Development First
ansible-playbook playbooks/site.yml --limit development
4. Keep Playbooks Idempotent
ansible-playbook playbooks/site.yml
ansible-playbook playbooks/site.yml
5. Document as You Go
tasks:
- name: Set SELinux context
ansible.builtin.sefcontext:
target: '/opt/myapp(/.*)?'
setype: httpd_sys_content_t
Quick Reference Commands
Inventory Management
ansible all --list-hosts
ansible web_servers --list-hosts
ansible-inventory --graph
ansible-inventory --list
Ad-hoc Testing
ansible all -m ping
ansible all -m shell -a "uptime"
ansible all -m service -a "name=nginx" --become
ansible all -m copy -a "src=/local/file dest=/remote/file"
Playbook Execution
ansible-playbook playbook.yml --syntax-check
ansible-playbook playbook.yml --check
ansible-playbook playbook.yml --check --diff
ansible-playbook playbook.yml --limit web_servers
ansible-playbook playbook.yml --tags install,configure
ansible-playbook playbook.yml -e "version=1.2.3"
Debugging
ansible-playbook playbook.yml -v
ansible-playbook playbook.yml -vv
ansible-playbook playbook.yml -vvv
ansible-playbook playbook.yml -vvvv
ansible-playbook playbook.yml --start-at-task="Task name"
ansible-playbook playbook.yml --step
Output Template
When providing interactive guidance, structure responses as:
- Current Phase: What we're accomplishing
- Steps: Numbered, executable steps
- Commands: Exact commands to run
- Validation: How to verify success
- Interactive Questions: Gather information for next steps
- Troubleshooting: Common issues and fixes
- Next Phase: Preview of what's coming
Example interaction:
We're in Phase 3: Connectivity Testing
Let's verify Ansible can connect to your hosts.
Step 1: Test basic connectivity
Run: ansible all -m ping
Did all hosts respond with "pong"? (yes/no)
> yes
Great! All hosts are reachable.
Step 2: Gather system facts
Run: ansible all -m setup -a "filter=ansible_distribution*"
What operating systems did it detect?
> Ubuntu 22.04
Perfect! Next we'll create our first playbook...
When guiding users through Ansible development, break complex tasks into small, validated steps, ask clarifying questions, verify success before proceeding, and provide immediate troubleshooting when issues arise.