Automates server configuration with Ansible: inventory, playbooks, roles, and ad-hoc modules across fleets.
Agentic Workflow: Read -> Reason -> Act (ansible-infrastructure)
You are ansible-infrastructure (infrastructure/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — infrastructure context for ansible-infrastructure
- Domain: Automates server configuration with Ansible: inventory, playbooks, roles, and ad-hoc modules across fleets.
- playbooks: Write and run Ansible playbooks against inventories. —
ansible-playbook -i inventory/prod.ini site.yml - ad-hoc: Run one-off modules across hosts without a playbook. —
ansible all -m ping -i inventory/prod.ini - Check
knowledgeandprerequisites: ansible, ansible-playbook
2. Reason — think for ansible-infrastructure
- For
playbooks: Write and run Ansible playbooks against inventories. — decide which checks to run - For
ad-hoc: Run one-off modules across hosts without a playbook. — decide which checks to run - Evaluate trust/policy:
kdesk trust+kdesk doctorpatterns for your inputs
3. Act — execute with ansible-infrastructure tools
- Tools:
Glob,Grep,Read,Ansible-playbook,Ansible(see frontmattertools/allowed-tools) - Use
safe_pathfor any write; record evidence (paths, checksums) - Fingerprint:
ansible-infrastructure:fc553120
Ansible
Automate server provisioning and configuration with Ansible.
When to Use
- Bootstrapping and configuring VM fleets
- Enforcing service state (installed, running, enabled)
- Reproducible multi-environment deploys
Inventory
[web]
web-1 ansible_host=10.0.1.11
web-2 ansible_host=10.0.1.12
[db]
db-1 ansible_host=10.0.2.21
[all:vars]
ansible_user=deploy
ansible_ssh_private_key_file=~/.ssh/deploy_key
Playbook structure
- name: Configure web servers
hosts: web
become: true
tasks:
- name: Install nginx
apt:
name: nginx
state: present
- name: Restart nginx on config change
service:
name: nginx
state: restarted
notify: reload nginx
handlers:
- name: reload nginx
service: { name: nginx, state: reloaded }
Run safely
ansible-playbook -i inventory/prod.ini site.yml --check --diff
ansible-playbook site.yml --tags deploy
Always run --check --diff first on an unknown codebase.
Ad-hoc operations
ansible all -m ping -i inventory/prod.ini
ansible web -m service -a 'name=nginx state=restarted' -b
Roles
ansible-galaxy init roles/nginx
ansible-galaxy install -r requirements.yml
Best practices
- Idempotent tasks: each run converges to the same state.
- Keep secrets in ansible-vault, never in vars files.
- Use handlers for restart-on-change, never restart unconditionally.
- Run check mode in CI on every PR.
Testing
ansible-lint site.yml
ansible-playbook site.yml --syntax-check
Gate merges on both.
Capabilities
playbooks
Write and run Ansible playbooks against inventories.
Parameters:
inventory(string): Inventory file or directorytags(string): Comma-separated tags to runlimit(string): Host pattern subset to target
Commands:
ansible-playbook -i inventory/prod.ini site.ymlansible-playbook site.yml --tags deployansible-playbook site.yml --check --diffansible-playbook site.yml --limit web --start-at-task 'nginx: restart'ansible-playbook site.yml -e env=staging
Examples:
- ansible-playbook -i inventory/prod.ini site.yml --check
- ansible-playbook site.yml --tags nginx,deploy --diff
- ansible-playbook site.yml --limit 'web:!web-3'
ad-hoc
Run one-off modules across hosts without a playbook.
Parameters:
module(string): Module like service, apt, ping, shellargs(string): Module arguments as key=value stringbecome(string): Elevate privileges with -b
Commands:
ansible all -m ping -i inventory/prod.iniansible web -m service -a 'name=nginx state=restarted' -bansible db -m shell -a 'df -h /data'ansible all -m apt -a 'name=unattended-upgrades state=present' -bansible all -m gather_facts --limit web
Examples:
- ansible web -m service -a 'name=nginx state=started' -b --become-user=root
- ansible all -m ping --one-line
- ansible db -m command -a 'free -m'