$npx -y skills add ancoleman/ai-design-components --skill managing-configurationGuide users through creating, managing, and testing server configuration automation using Ansible. When automating server configurations, deploying applications with Ansible playbooks, managing dynamic inventories for cloud environments, or testing roles with Molecule, this skill
| 1 | # Configuration Management |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | This skill provides guidance for automating server and application configuration using Ansible and related tools. It covers playbook creation, role structure, inventory management (static and dynamic), secret management, testing patterns, and idempotency best practices to ensure safe, repeatable configuration deployments. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Invoke this skill when: |
| 10 | - Creating Ansible playbooks to configure servers or deploy applications |
| 11 | - Structuring reusable Ansible roles with proper directory layout |
| 12 | - Managing inventories (static files or dynamic cloud-based) |
| 13 | - Securing secrets with ansible-vault or HashiCorp Vault integration |
| 14 | - Testing roles with Molecule before production deployment |
| 15 | - Ensuring idempotent playbooks that safely run multiple times |
| 16 | - Migrating from Chef or Puppet to Ansible |
| 17 | - Implementing GitOps workflows for configuration as code |
| 18 | - Debugging playbook failures or handler issues |
| 19 | |
| 20 | ## Quick Start |
| 21 | |
| 22 | ### Basic Playbook Example |
| 23 | |
| 24 | ```yaml |
| 25 | --- |
| 26 | # site.yml |
| 27 | - name: Configure web servers |
| 28 | hosts: webservers |
| 29 | become: yes |
| 30 | |
| 31 | tasks: |
| 32 | - name: Ensure nginx is installed |
| 33 | apt: |
| 34 | name: nginx |
| 35 | state: present |
| 36 | notify: Restart nginx |
| 37 | |
| 38 | - name: Start nginx service |
| 39 | service: |
| 40 | name: nginx |
| 41 | state: started |
| 42 | enabled: yes |
| 43 | |
| 44 | handlers: |
| 45 | - name: Restart nginx |
| 46 | service: |
| 47 | name: nginx |
| 48 | state: restarted |
| 49 | ``` |
| 50 | |
| 51 | Run with: |
| 52 | ```bash |
| 53 | ansible-playbook -i inventory/production site.yml |
| 54 | ``` |
| 55 | |
| 56 | ## Core Concepts |
| 57 | |
| 58 | ### 1. Idempotency |
| 59 | |
| 60 | Run playbooks multiple times without unintended side effects. Use state-based modules (`present`, `started`, `latest`) instead of imperative commands. |
| 61 | |
| 62 | **Idempotent (good):** |
| 63 | ```yaml |
| 64 | - name: Ensure package installed |
| 65 | apt: |
| 66 | name: nginx |
| 67 | state: present |
| 68 | ``` |
| 69 | |
| 70 | **Not idempotent (avoid):** |
| 71 | ```yaml |
| 72 | - name: Install package |
| 73 | command: apt-get install -y nginx |
| 74 | ``` |
| 75 | |
| 76 | See `references/idempotency-guide.md` for detailed patterns. |
| 77 | |
| 78 | ### 2. Inventory Management |
| 79 | |
| 80 | **Static Inventory:** INI or YAML files for stable environments. |
| 81 | **Dynamic Inventory:** Scripts or plugins for cloud environments (AWS, Azure, GCP). |
| 82 | |
| 83 | Example static inventory (INI): |
| 84 | ```ini |
| 85 | [webservers] |
| 86 | web1.example.com ansible_host=10.0.1.10 |
| 87 | web2.example.com ansible_host=10.0.1.11 |
| 88 | |
| 89 | [webservers:vars] |
| 90 | nginx_worker_processes=4 |
| 91 | ``` |
| 92 | |
| 93 | See `references/inventory-management.md` for dynamic inventory setup. |
| 94 | |
| 95 | ### 3. Roles vs Playbooks |
| 96 | |
| 97 | **Playbooks:** Orchestrate multiple tasks and roles for specific deployments. |
| 98 | **Roles:** Reusable, self-contained configuration units with standardized directory structure. |
| 99 | |
| 100 | Standard role structure: |
| 101 | ``` |
| 102 | roles/nginx/ |
| 103 | ├── defaults/ # Default variables |
| 104 | ├── tasks/ # Task files |
| 105 | ├── handlers/ # Change handlers |
| 106 | ├── templates/ # Jinja2 templates |
| 107 | ├── files/ # Static files |
| 108 | └── meta/ # Dependencies |
| 109 | ``` |
| 110 | |
| 111 | See `references/role-structure.md` for complete role patterns. |
| 112 | |
| 113 | ### 4. Secret Management |
| 114 | |
| 115 | **ansible-vault:** Built-in encryption for sensitive data. |
| 116 | **HashiCorp Vault:** Enterprise-grade secrets management with dynamic credentials. |
| 117 | |
| 118 | Encrypt secrets: |
| 119 | ```bash |
| 120 | ansible-vault create group_vars/all/vault.yml |
| 121 | ansible-playbook site.yml --ask-vault-pass |
| 122 | ``` |
| 123 | |
| 124 | See `references/secrets-management.md` for Vault integration. |
| 125 | |
| 126 | ## Common Workflows |
| 127 | |
| 128 | ### Workflow 1: Create New Playbook |
| 129 | |
| 130 | **Step 1:** Define inventory |
| 131 | ```ini |
| 132 | # inventory/production |
| 133 | [webservers] |
| 134 | web1.example.com |
| 135 | web2.example.com |
| 136 | ``` |
| 137 | |
| 138 | **Step 2:** Create playbook structure |
| 139 | ```yaml |
| 140 | --- |
| 141 | - name: Configure application |
| 142 | hosts: webservers |
| 143 | become: yes |
| 144 | |
| 145 | pre_tasks: |
| 146 | - name: Update package cache |
| 147 | apt: |
| 148 | update_cache: yes |
| 149 | |
| 150 | roles: |
| 151 | - common |
| 152 | - application |
| 153 | |
| 154 | post_tasks: |
| 155 | - name: Verify service |
| 156 | uri: |
| 157 | url: http://localhost:8080/health |
| 158 | status_code: 200 |
| 159 | ``` |
| 160 | |
| 161 | **Step 3:** Test with check mode |
| 162 | ```bash |
| 163 | ansible-playbook -i inventory/production site.yml --check --diff |
| 164 | ``` |
| 165 | |
| 166 | **Step 4:** Execute playbook |
| 167 | ```bash |
| 168 | ansible-playbook -i inventory/production site.yml |
| 169 | ``` |
| 170 | |
| 171 | See `references/playbook-patterns.md` for advanced patterns. |
| 172 | |
| 173 | ### Workflow 2: Create and Test Role |
| 174 | |
| 175 | **Step 1:** Initialize role structure |
| 176 | ```bash |
| 177 | ansible-galaxy init roles/myapp |
| 178 | ``` |
| 179 | |
| 180 | **Step 2:** Define tasks |
| 181 | ```yaml |
| 182 | # roles/myapp/tasks/main.yml |
| 183 | --- |
| 184 | - name: Install application dependencies |
| 185 | apt: |
| 186 | name: "{{ item }}" |
| 187 | state: present |
| 188 | loop: "{{ myapp_dependencies }}" |
| 189 | |
| 190 | - name: Deploy application |
| 191 | template: |
| 192 | src: app.conf.j2 |
| 193 | dest: /etc/myapp/app.conf |
| 194 | notify: Restart myapp |
| 195 | ``` |
| 196 | |
| 197 | **Step 3:** Add handler |
| 198 | ``` |