ansible

jpoutrin's avatarfrom jpoutrin

Ansible automation and configuration management patterns. Use when writing Ansible playbooks, roles, or automating infrastructure configuration and deployment tasks.

⭐0stars🔀0forks📁View on GitHub🕐Updated Dec 9, 2025

When & Why to Use This Skill

This Claude skill provides comprehensive Ansible automation and configuration management patterns, designed to streamline the creation of playbooks, roles, and infrastructure-as-code tasks. It emphasizes industry best practices such as idempotency, modular role structures, and the use of fully qualified collection names to ensure reliable and scalable IT automation.

Use Cases

  • Automated Server Provisioning: Rapidly deploy and configure web servers (like Nginx) across multiple environments using standardized, reusable playbooks.
  • Infrastructure as Code (IaC) Organization: Structure complex automation projects into modular roles with dedicated directories for tasks, handlers, and templates for better maintainability.
  • Configuration Consistency and Idempotency: Ensure system states remain consistent by implementing tasks that only apply changes when necessary, preventing unintended side effects during repeated runs.
  • Multi-Environment Inventory Management: Orchestrate deployments across development, staging, and production environments using hierarchical inventory structures and group variables.
nameansible
descriptionAnsible automation and configuration management patterns. Use when writing Ansible playbooks, roles, or automating infrastructure configuration and deployment tasks.

Ansible Skill

This skill provides Ansible automation patterns and best practices.

Playbook Structure

---
- name: Configure web servers
  hosts: webservers
  become: true
  vars:
    http_port: 80

  tasks:
    - name: Install nginx
      ansible.builtin.apt:
        name: nginx
        state: present
      notify: Restart nginx

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

Role Structure

roles/
└── webserver/
    ├── defaults/main.yml    # Default variables
    ├── handlers/main.yml    # Handler definitions
    ├── tasks/main.yml       # Task list
    ├── templates/           # Jinja2 templates
    ├── files/               # Static files
    └── vars/main.yml        # Role variables

Best Practices

Use Fully Qualified Collection Names

# ✅ Good
- ansible.builtin.apt:
    name: nginx

# ❌ Bad (ambiguous)
- apt:
    name: nginx

Idempotent Tasks

# Tasks should be safe to run multiple times
- name: Ensure config exists
  ansible.builtin.template:
    src: config.j2
    dest: /etc/app/config.yml
  # Only changes if content differs

Use Handlers for Service Restarts

tasks:
  - name: Update config
    template:
      src: nginx.conf.j2
      dest: /etc/nginx/nginx.conf
    notify: Restart nginx

handlers:
  - name: Restart nginx
    service:
      name: nginx
      state: restarted

Inventory Best Practices

[webservers]
web1.example.com
web2.example.com

[dbservers]
db1.example.com

[production:children]
webservers
dbservers