/iac-automation-skills:ansible-playbook-and-role-designfrom iac-automation-skills
Designs and safely runs Ansible playbooks, roles, and inventories for configuration management, including idempotent task design, Ansible Vault for secrets, and deciding between Ansible vs Terraform/CloudFormation.
Ships in iac-automation-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Ansible manages the configuration of already-existing hosts — installed
packages, running services, config files, users — by describing desired
state as YAML tasks and applying them idempotently over SSH/WinRM with no
agent required on the target. This complements, rather than replaces,
provisioning tools: Terraform/CloudFormation create the VM, network, and
IAM role that a host needs to exist; Ansible then configures what runs on
that host once it's there. See
infrastructure-as-code-terraform
for the provisioning side of that split, and
aws-cloudformation-templates
for the AWS-native equivalent. The operational risk Ansible manages is
twofold: idempotency (running the same playbook twice should converge to
the same state, not double-apply changes) and blast radius (a playbook
targets an inventory, and a wrong inventory or missing --limit can apply
a change to every production host at once).
ansible-core ≥ 2.15 — the
collection-based distribution (ansible meta-package pulling in
ansible.builtin plus community collections) is standard since Ansible
2.10; confirm which collections a role depends on (e.g.
community.general, amazon.aws) are installed via
ansible-galaxy collection install.ansible-lint and yamllint for static checks; molecule (with a
Docker or Podman driver) for role testing is recommended for any role
used beyond a single one-off playbook.sudo/become rights the playbook's tasks actually need, not
unrestricted root.Structure inventory by environment, not by one flat host list:
inventories/
staging/
hosts.yml
group_vars/
all.yml
webservers.yml
prod/
hosts.yml
group_vars/
all.yml
webservers.yml
roles/
nginx/
tasks/main.yml
handlers/main.yml
templates/nginx.conf.j2
defaults/main.yml
meta/main.yml
playbooks/
site.yml
inventories/staging/hosts.yml:
all:
children:
webservers:
hosts:
web-staging-01.example.internal:
web-staging-02.example.internal:
Running against the wrong environment becomes a conscious -i choice,
not an accident of a shared host list.
Write roles with idempotency as the default, not an afterthought.
Prefer built-in modules (which are idempotent by design) over shell/
command, which are not idempotent unless explicitly guarded:
# roles/nginx/tasks/main.yml
- name: Install nginx
ansible.builtin.package:
name: nginx
state: present
- name: Deploy nginx site config
ansible.builtin.template:
src: nginx.conf.j2
dest: /etc/nginx/sites-available/app.conf
owner: root
group: root
mode: "0644"
notify: Reload nginx
- name: Ensure nginx is enabled and running
ansible.builtin.service:
name: nginx
state: started
enabled: true
# roles/nginx/handlers/main.yml
- name: Reload nginx
ansible.builtin.service:
name: nginx
state: reloaded
The handler only fires when template actually changes the file, so
re-running the playbook with no drift performs zero changes and
reports changed=0 — the signal that the role is truly idempotent.
If a shell/command task is unavoidable (no module covers the
action), guard it explicitly:
- name: Run one-time migration marker check
ansible.builtin.command: /opt/app/bin/migrate --check
register: migrate_check
changed_when: "'pending' in migrate_check.stdout"
failed_when: migrate_check.rc not in [0, 1]
Use defaults/main.yml for overridable role inputs, and
group_vars/host_vars for environment-specific values, so the same
role runs unmodified in every environment:
# roles/nginx/defaults/main.yml
nginx_worker_connections: 1024
nginx_client_max_body_size: "10m"
# inventories/prod/group_vars/webservers.yml
nginx_worker_connections: 4096
Encrypt secrets with Ansible Vault — never plaintext credentials in a playbook or inventory. Show the pattern, not a real vault password:
ansible-vault create group_vars/prod/vault.yml
# Editor opens; contents are encrypted at rest once saved, e.g.:
# vault_db_password: "REPLACE_WITH_ACTUAL_SECRET"
Reference the vaulted variable from a plain (non-encrypted) variable so
group_vars/prod/vault.yml stays fully encrypted while
group_vars/prod/vars.yml stays diffable in version control:
# group_vars/prod/vars.yml (plaintext, safe to commit)
db_password: "{{ vault_db_password }}"
Run with the vault password supplied out-of-band (a password manager,
CI secret store, or --vault-password-file pointing at a file that is
itself not committed):
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--vault-password-file /run/secrets/ansible-vault-pass
Dry-run before any production apply.
Warning: Running
ansible-playbookagainst a production inventory without--checkfirst (and ideally--diffto see exact file/content changes) risks applying an untested task to every host in that inventory simultaneously — there is no automatic rollback if a task mid-playbook breaks a service. Always dry-run and scope first:
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--check --diff --limit webservers
Review the check-mode output (changed/ok counts and the --diff
content), then run for real against a narrow slice before the whole
fleet:
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--limit "web-prod-01.example.internal"
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml
Note that --check is not a perfect predictor for every module —
modules that depend on runtime state produced by earlier tasks in the
same run (e.g. a file created by a prior task) may report inaccurately
in check mode; treat it as a strong signal, not an absolute guarantee.
Compose roles into playbooks by responsibility, not by environment:
# playbooks/site.yml
- name: Configure web tier
hosts: webservers
become: true
roles:
- role: nginx
- role: app-runtime
Know when to reach for a provisioning tool instead. If the task is
"create this EC2 instance/VPC/RDS database," that's Terraform/
CloudFormation territory (see
infrastructure-as-code-terraform
and
aws-cloudformation-templates).
If the task is "this host exists — install/configure/run something on
it," that's Ansible. Many pipelines chain both: Terraform/CloudFormation
provisions and outputs an inventory (e.g. via a dynamic inventory plugin
like amazon.aws.aws_ec2, tag-filtered), then Ansible configures the
result. Avoid using Ansible's ec2_instance-style modules to also
own long-lived infrastructure lifecycle in parallel with a provisioning
tool — pick one owner per resource to avoid both tools fighting over
the same object.
nginx, app-runtime,
monitoring-agent) rather than one monolithic webserver role that
bundles unrelated concerns — smaller roles are independently testable
and composable across playbooks.requirements.yml with explicit
versions, and run ansible-galaxy install -r requirements.yml in CI
before every run so a role doesn't silently pick up a breaking upstream
change.ansible-lint and yamllint in CI on every PR touching playbooks/
roles — most idempotency and style issues (bare shell where a module
exists, missing become, unpinned package versions) are caught
statically before ever touching a host.serial: in a playbook targeting many hosts to roll out changes in
batches rather than all at once, giving a chance to halt on early
failures:
- hosts: webservers
serial: "25%"
max_fail_percentage: 10
tags: [nginx, config]) so a targeted --tags/--skip-tags
run is possible without executing an entire playbook for a small fix.molecule test to run a role's task list against a disposable
container/VM in CI, asserting both convergence and idempotency (a
second molecule converge run should report zero changes).Symptom: Re-running a playbook that already succeeded reports
changed on tasks that shouldn't have anything left to do.
Fix: Usually a shell/command task without a changed_when
guard, or a template/lineinfile task whose rendered output isn't
byte-stable (e.g. embeds a timestamp). Replace shell/command with
the equivalent built-in module where one exists, and add an explicit
changed_when condition when it doesn't.
Symptom: A playbook meant for staging accidentally runs against
every host including prod because of a shared inventory group name.
Fix: Use fully separate inventory files/directories per environment
(as in step 1), not one inventory with environment as just a variable,
and always pass -i <specific-inventory> explicitly rather than
relying on an ansible.cfg default that could point anywhere.
Symptom: ansible-vault-encrypted variables show up as ciphertext
errors ("Decryption failed") when running from CI.
Fix: The vault password isn't reaching the CI runner, or multiple
vault IDs are in use without --vault-id disambiguating them. Confirm
the CI job injects --vault-password-file (backed by the CI's secret
store, never a file committed to the repo) and that the vault ID label
matches what encrypted the variable if multiple vault passwords are in
play.
Symptom: A task that installs a package works on one host group but
fails with "package not found" on another.
Fix: The role likely hardcodes a package manager module (apt,
yum) instead of the cross-platform package/dnf/apt abstraction,
or assumes a specific OS family. Use ansible.builtin.package where
behavior is uniform enough, and gate OS-specific tasks with
when: ansible_facts['os_family'] == "Debian" (or the equivalent).
Symptom: A large playbook run against 200 hosts fails on host #40,
and there's no clear way to know what state the first 39 vs. remaining
161 hosts are in.
Fix: This indicates the playbook wasn't run with serial: batching
or --limit scoping. Re-run with a smaller --limit slice, review
ansible-playbook ... --check --diff output first next time, and add
serial: with max_fail_percentage to the playbook so a systemic
failure halts after a bounded number of hosts instead of continuing
through the whole inventory.
Scenario: Roll out an updated nginx configuration (a new
client_max_body_size) to the webservers group in prod, with a
vault-encrypted TLS certificate passphrase referenced by the role, dry-run
first, then a batched rollout.
roles/nginx/templates/nginx.conf.j2:
server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/app.crt;
ssl_certificate_key /etc/nginx/ssl/app.key;
client_max_body_size {{ nginx_client_max_body_size }};
}
inventories/prod/group_vars/webservers/vault.yml (encrypted with
ansible-vault create, shown here only as the pattern — replace with a
real vault-managed secret, never commit plaintext):
vault_tls_passphrase: "REPLACE_WITH_ACTUAL_SECRET"
inventories/prod/group_vars/webservers/vars.yml (plaintext, safe to
commit):
nginx_client_max_body_size: "25m"
tls_passphrase: "{{ vault_tls_passphrase }}"
playbooks/site.yml:
- name: Configure web tier
hosts: webservers
become: true
serial: "25%"
max_fail_percentage: 10
roles:
- role: nginx
Dry run, then batched rollout:
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--vault-password-file /run/secrets/ansible-vault-pass \
--check --diff --limit webservers
# Review: 12 hosts, "changed: nginx.conf client_max_body_size 10m -> 25m",
# 0 failures.
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--vault-password-file /run/secrets/ansible-vault-pass
# serial: 25% => 3 hosts at a time; halts automatically if failures
# exceed 10% of the batch.
A follow-up idempotency check confirms convergence:
ansible-playbook -i inventories/prod/hosts.yml playbooks/site.yml \
--vault-password-file /run/secrets/ansible-vault-pass
# PLAY RECAP: changed=0 across all 12 hosts.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
14 skills in this plugin
/aws-cloudformation-templatesAuthors and safely operates AWS CloudFormation templates (YAML/JSON), including stacks, change sets, nested and cross-stack references, StackSets for multi-account/multi-region deployment, and drift detection. Use when the user asks to "write a CloudFormation template for X," "structure nested CloudFormation stacks," "deploy the same stack across AWS accounts/regions," "review a CloudFormation change set before applying," "detect/reconcile drift on a stack," or "migrate/compare CloudFormation with Terraform" for an AWS-native IaC choice.
/chef-puppet-saltstack-legacy-config-managementProvides a comparative overview of Chef, Puppet, and SaltStack for teams maintaining existing legacy configuration-management estates alongside or instead of Ansible — agent-based pull architecture, DSL/resource models (Chef recipes/cookbooks, Puppet manifests/catalogs, Salt states/pillars), and a candid assessment of where each still earns its keep in a modern enterprise versus where it's inertia. Use when the user asks to "maintain this existing Chef/Puppet/Salt estate," "write a Chef recipe/Puppet manifest/Salt state," "should we migrate off Puppet to Ansible," "why is our Puppet run applying a change we didn't expect," or "compare Chef vs. Puppet vs. SaltStack."
/feature-flag-configuration-launchdarkly-and-unleashDesigns and operates feature flag configuration with LaunchDarkly or Unleash, covering flag lifecycle (create, target, roll out, retire), kill-switch patterns for fast incident mitigation without a redeploy, targeting/segmentation rules, and cleaning up stale flag debt before it accumulates into unreadable conditional logic. Use when the user asks to "add a feature flag for X," "set up a kill switch for this feature," "configure LaunchDarkly/Unleash targeting rules," "roll out a flag gradually by percentage," "clean up old feature flags," or "should we use LaunchDarkly or self-host Unleash."
/gremlin-chaos-engineering-configurationConfigures Gremlin-specific chaos engineering attacks — installing the Gremlin agent/sidecar, defining resource, state, and network attacks via the Gremlin API/CLI or Terraform provider, scoping blast radius with targets and halt conditions, and running Gremlin Scenarios for multi-step failure sequences. Use when the user asks to "configure a Gremlin attack," "set up the Gremlin agent in Kubernetes/EC2," "write a Gremlin Scenario," "scope a Gremlin blast radius/halt condition," or "use Gremlin to test our failover." For the general chaos-engineering principles (steady-state hypothesis, game days, tool-agnostic blast radius scoping) this configures against, use the SRE chaos-engineering-and-resilience-testing skill instead.
/infrastructure-post-deployment-validation-and-smoke-testingVerifies that a Terraform apply, CloudFormation deploy, or Ansible playbook run actually produced working infrastructure — resource existence and configuration checks, connectivity/health smoke tests, and automated post-apply assertions — rather than treating a clean "apply succeeded" exit code as proof the system works. Use when the user asks to "verify this deployment actually worked," "write a smoke test after terraform apply/cloudformation deploy," "check the resource is actually reachable/configured correctly post-deploy," "add post-deployment validation to the pipeline," or "our apply succeeded but the service is down."
/makefile-authoring-and-validationAuthors Makefiles as a build/automation entry point for ops tasks — `.PHONY` target conventions, dependency graphs between targets, variable/default handling, and self-documenting `help` targets — and validates them with `make -n` (dry-run) and `checkmake`/shellcheck-style linting before they're relied on in CI or by other engineers. Use when the user asks to "write a Makefile for this project," "add a build/lint/ test target to the Makefile," "why does `make` rebuild everything every time," "make targets phony," or "lint/validate this Makefile."
npx claudepluginhub selvarajmurugesan90/ops-engineering-skills --plugin iac-automation-skillsOther plugins' skills for the same job