Ansible Idempotency Check
Use when an Ansible role under roles/ has been modified and needs testing for idempotency. Triggers on changed roles detected via git status, test role, verify role, check idempotent.
Get the complete skill folder, including its scripts and reference files.
When to use this skill
Use Ansible Idempotency Check when an AI agent needs a reusable SKILL.md workflow for this job: Use when an Ansible role under roles/ has been modified and needs testing for idempotency. Triggers on changed roles detected via git status, test role, verify role, check idempotent.
When not to use it
Skip Ansible Idempotency Check when the task is outside the coding category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/ansible-idempotency-check # Save SKILL.md to ~/.claude/skills/ansible-idempotency-check/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/ansible-idempotency-check/SKILL.md. For a shared project, commit the folder at .claude/skills/ansible-idempotency-check/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Ansible Idempotency Check skill for this task: After modifying any role under roles/. Confirm any required inputs or files before making changes.
What supports this recommendation?
79/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 87/100
- Practical detail
- 92/100
- Source evidence
- 52/100
- Source signals
- 72/100
Model compatibility evidence
- claudeinferred
The skill text mentions Claude or a closely associated term. This is keyword-derived compatibility; no hands-on model test is recorded.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# Test Role
## Overview
Tests modified Ansible roles for idempotency by running them twice using `ansible localhost -m include_role`. A correct role should produce no changes on the second run.
**Safety warning:** This skill runs roles against the live host — it will install or modify real software on your Mac. Review the role's diff before running.
## When to Use
- After modifying any role under `roles/` - When asked to test, verify, or validate a role - Before committing role changes
## Procedure
**Important:** All commands must be run from the git repo root. `cd` there first:
```bash cd "$(git rev-parse --show-toplevel)" ```
### 1. Detect Changed Roles and Roles Directory
Run `git status --short` and extract both the roles directory path and role names from paths matching `<prefix>/roles/<name>/`.
```bash git status --short | sed -n 's|.* \(.*/\)\{0,1\}roles/\([^/]*\)/.*|\1roles \2|p' | sort -u ```
Example output (the first field is the roles directory, the second is the role name):
- `roles docker` — roles dir is `roles`, role name is `docker` - `infra/ansible/roles nodejs` — roles dir is `infra/ansible/roles`, role name is `nodejs`
Extract the roles directory (all changed roles share the same one):
```bash roles_dir=$(git status --short | sed -n 's|.* \(.*/\)\{0,1\}roles/[^/]*/.*|\1roles|p' | sort -u | head -1) ```
If `roles_dir` is empty, default to `roles`. This captures all statuses (modified, added, renamed, untracked). Deleted roles are included in the output but should be skipped — there is nothing to test.
The `ANSIBLE_ROLES_PATH` env var must be set to the detected roles directory so Ansible can find roles by name.
### 2. First Run — Apply the Role
For each changed role, run it using `include_role`:
```bash ANSIBLE_ROLES_PATH=./$roles_dir ansible localhost -m include_role -a name=<role-name> -vv ```
Replace `<role-name>` with the actual role name, e.g. `docker`.
**Check the exit code.** If the first run fails (non-zero exit), stop and report the failure. Do not proceed to the second run.
Some roles may require sudo. If you see permission errors, re-run with `--become -K` (or just `--become` if passwordless sudo is configured).
### 3. Second Run — Check Idempotency
Run the same command again, capturing output:
```bash output=$(ANSIBLE_ROLES_PATH=./$roles_dir ansible localhost -m include_role -a name=<role-name> -vv 2>&1) echo "$output" ```
Check idempotency by looking for `CHANGED` in the output:
```bash echo "$output" | grep -c 'CHANGED' ```
- **Count is 0** → Role is idempotent. All tasks report `SUCCESS`. - **Count > 0** → Role is NOT idempotent. Find which tasks changed:
```bash echo "$output" | grep 'CHANGED' ```
**Output format reference (`ansible -m include_role` at `-vv`):**
The first result block is always the `include_role` task itself — it always shows `"changed": false` and can be ignored. Subsequent result blocks are the actual role tasks:
- Unchanged tasks: `localhost | SUCCESS => {"changed": false, ...}` - Changed tasks: `localhost | CHANGED => {"changed": true, ...}`
## Reporting
For each role tested, report: - Role name - First run: success/failure (with error summary if failed) - Second run: idempotent (no changes) or non-idempotent (list which tasks changed)
## Common Causes of Non-Idempotency
- Using `shell`/`command` modules without `creates`/`removes` guards - Using `state: latest` with Homebrew, pip, or npm (may re-download or report changed when already at latest) - File operations without proper `when` conditions - Missing `changed_when: false` on read-only commands (but audit existing uses — `changed_when: false` on a task that actually makes changes hides real non-idempotency)
Intended uses
- After modifying any role under roles/
- When asked to test, verify, or validate a role
- Before committing role changes
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.