areas/devops/infrastructure/skills/ansible-playbooks/SKILL.md
Write idempotent Ansible playbooks and roles for server configuration, K8s node provisioning, and application bootstrap.
npx skillsauth add sawrus/agent-guides ansible-playbooksInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Expertise: Idempotent roles, inventory patterns, Vault integration, molecule testing, bare-metal K8s node prep.
When configuring bare-metal servers, provisioning K8s nodes, managing OS-level config, or rotating OS credentials.
roles/base-server/
├── tasks/
│ ├── main.yml ← imports sub-task files
│ ├── packages.yml
│ ├── sysctl.yml
│ └── users.yml
├── defaults/
│ └── main.yml ← all variables with sensible defaults
├── vars/
│ └── main.yml ← internal constants (not overridable)
├── templates/
│ └── sysctl.conf.j2
├── handlers/
│ └── main.yml ← restart services on change
└── meta/
└── main.yml ← role dependencies
# ✅ Package install — idempotent
- name: Install required packages
ansible.builtin.apt:
name:
- containerd
- curl
- jq
state: present
update_cache: true
when: ansible_os_family == "Debian"
# ✅ File with checksum validation — only copies if changed
- name: Configure containerd
ansible.builtin.template:
src: containerd-config.toml.j2
dest: /etc/containerd/config.toml
owner: root
group: root
mode: "0644"
notify: Restart containerd # handler only fires if file changed
# ✅ Service management
- name: Enable and start containerd
ansible.builtin.systemd:
name: containerd
enabled: true
state: started
daemon_reload: true
# handlers/main.yml
- name: Restart containerd
ansible.builtin.systemd:
name: containerd
state: restarted
- name: Reload sysctl
ansible.builtin.command: sysctl --system
changed_when: false
# inventory/production/hosts.ini
[control_plane]
cp-01 ansible_host=192.168.10.10
cp-02 ansible_host=192.168.10.11
cp-03 ansible_host=192.168.10.12
[workers]
worker-01 ansible_host=192.168.10.20
worker-02 ansible_host=192.168.10.21
[k8s_cluster:children]
control_plane
workers
[k8s_cluster:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/infra-key
ansible_python_interpreter=/usr/bin/python3
# Encrypt a vars file
ansible-vault encrypt group_vars/all/vault.yml
# Inline encrypted variable
ansible-vault encrypt_string 'supersecretpassword' --name 'db_password'
# group_vars/all/vault.yml (encrypted)
vault_db_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
...
# group_vars/all/vars.yml (plain, references vault vars)
db_password: "{{ vault_db_password }}"
# playbooks/k8s-node-prep.yml
---
- name: Prepare K8s nodes
hosts: k8s_cluster
become: true
roles:
- role: base-server # OS hardening, packages
- role: k8s-prereqs # swap off, kernel modules, sysctl
- role: containerd # install + configure containerd
- role: kubeadm-install # install kubeadm, kubelet, kubectl (pinned)
# Dry run (check mode)
ansible-playbook -i inventory/production/hosts.ini \
playbooks/k8s-node-prep.yml --check --diff
# Run with vault password
ansible-playbook -i inventory/production/hosts.ini \
playbooks/k8s-node-prep.yml \
--vault-password-file ~/.ansible-vault-password
# Limit to specific hosts
ansible-playbook -i inventory/production/hosts.ini \
playbooks/k8s-node-prep.yml \
--limit "worker-01,worker-02"
# Tags for partial runs
ansible-playbook ... --tags "packages,sysctl" --skip-tags "users"
# Lint (enforce best practices)
ansible-lint playbooks/k8s-node-prep.yml
# Molecule test (spins container, runs playbook, verifies)
cd roles/base-server && molecule test
testing
QA Expert for writing E2E tests, test scenarios, test plans, and ensuring test coverage quality.
development
Expert UI/UX design intelligence for creating distinctive, high-craft, and mobile-first interfaces. Focuses on premium aesthetics, touch-first ergonomics, and Flutter performance.
development
Code Review Expert for static analysis, security auditing, architecture review, and ensuring code quality standards.
development
Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep watching open PRs so fresh review feedback is surfaced promptly. Use when the user asks Codex to monitor a PR, watch CI, handle review comments, or keep an eye on failures and feedback on an open PR.