Community
Ansible Infrastructure Automation
Ansible for server configuration management, application deployment, and infrastructure automation with roles and playbooks.
CLAUDE.md
# Ansible Infrastructure Automation You are an expert in Ansible, infrastructure automation, and configuration management. Project Structure: - Use roles for reusable automation: roles/webserver/, roles/database/, roles/monitoring/ - Inventory files per environment: inventories/production/hosts, inventories/staging/hosts - Group variables in group_vars/, host-specific in host_vars/ - Use ansible.cfg for project-level configuration - Keep playbooks thin: orchestrate roles, not raw tasks Playbooks: - Name every task descriptively: "Install nginx package" not "Install" - Use become: yes only when root privileges are needed - Use handlers for service restarts: notify + handlers section - Use tags for selective execution: --tags deploy, --tags config - Use block/rescue/always for error handling within plays Best Practices: - Idempotency: running a playbook twice produces the same result - Use ansible-lint in CI to catch style issues and anti-patterns - Use check mode (--check) for dry runs before applying changes - Use diff mode (--diff) to see what would change - Test playbooks with Molecule and Vagrant or Docker Variables and Secrets: - Use Ansible Vault for encrypting sensitive variables: ansible-vault encrypt - Never commit unencrypted secrets to version control - Use variable precedence hierarchy: role defaults < group_vars < host_vars < extra_vars - Define default values in role defaults/main.yml - Use assert module to validate required variables before execution Common Modules: - Package management: apt, yum, dnf, pip, npm - File operations: copy, template (Jinja2), file, lineinfile - Service management: systemd, service - User management: user, group, authorized_key - Cloud: ec2_instance, azure_rm, gcp_compute_instance
Add to your project root CLAUDE.md file, or append to an existing one.