ansible-playbooks
Use when writing and organizing Ansible playbooks for automated configuration management and infrastructure orchestration.
When & Why to Use This Skill
This Claude skill assists in creating, organizing, and optimizing Ansible playbooks for seamless infrastructure orchestration and automated configuration management. It provides comprehensive templates for inventory management, common modules like package installation and file operations, and enforces DevOps best practices such as role-based organization and idempotency to ensure reliable, repeatable deployments.
Use Cases
- Server Provisioning: Automating the installation and configuration of web servers (e.g., Nginx, Apache) and databases across multiple environments.
- Infrastructure as Code (IaC): Managing cloud resources and on-premise hardware using version-controlled Ansible scripts for better auditability.
- Application Deployment: Streamlining the deployment of software updates and configuration changes to production clusters with minimal downtime.
- Compliance and Security: Ensuring all servers maintain a consistent security posture and configuration state through automated enforcement and handlers.
| name | ansible-playbooks |
|---|---|
| description | Use when writing and organizing Ansible playbooks for automated configuration management and infrastructure orchestration. |
| allowed-tools | [] |
Ansible Playbooks
Writing and organizing Ansible playbooks for configuration management.
Basic Playbook
---
- name: Configure web servers
hosts: webservers
become: yes
vars:
http_port: 80
app_version: "1.0.0"
tasks:
- name: Install nginx
apt:
name: nginx
state: present
update_cache: yes
- name: Start nginx
service:
name: nginx
state: started
enabled: yes
- name: Deploy application
copy:
src: ./app
dest: /var/www/html
owner: www-data
mode: '0755'
Inventory
[webservers]
web1.example.com
web2.example.com
[databases]
db1.example.com
[production:children]
webservers
databases
Common Modules
Package Management
- name: Install packages
apt:
name:
- nginx
- git
- python3
state: present
File Operations
- name: Copy configuration
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
backup: yes
notify: Restart nginx
Handlers
handlers:
- name: Restart nginx
service:
name: nginx
state: restarted
Best Practices
Use Roles
roles/
├── webserver/
│ ├── tasks/
│ │ └── main.yml
│ ├── handlers/
│ │ └── main.yml
│ └── templates/
│ └── nginx.conf.j2
Idempotency
- name: Ensure directory exists
file:
path: /opt/app
state: directory
mode: '0755'