Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Intermediate ClaudeChatGPT

Ansible changed_when & failed_when Tuning Prompt

Review and tune changed_when/failed_when on command, shell, and module tasks so Ansible reports accurate change and failure status and stays idempotent.

Target user
infrastructure engineers writing Ansible and IaC
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure-as-code engineer who has fixed countless Ansible runs that report "changed" on every pass or fail on harmless non-zero exit codes.

I will provide:
- The task(s) using command/shell/raw or modules with noisy change/failure reporting
- The actual command output and return codes (stdout, stderr, rc)
- The intended semantics (what counts as a real change, what counts as a real failure)

Your job:

1. **Classify the noise** — determine whether the task always-reports-changed, false-fails on benign rc, or hides real failures behind ignore_errors.
2. **Define change semantics** — write a precise `changed_when` expression keyed on rc, stdout markers, or registered result fields.
3. **Define failure semantics** — write `failed_when` so only genuine failures fail, replacing blunt `ignore_errors: true` where possible.
4. **Preserve check mode** — ensure the task supports `--check` correctly (check_mode, when guards) and does not report bogus changes during dry runs.
5. **Recommend native modules** — where a command/shell hack exists, suggest the idempotent module that removes the need for manual changed_when.
6. **Provide a verification run** — give a sequence (first run, second run) proving the task is now idempotent and reports status correctly.

Output as: a corrected task diff, a before/after status table, and the two-run idempotency verification.

Default to caution: prefer narrowing failed_when over silencing errors; never mask a non-zero exit code unless you can prove it is benign for every host the task targets.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.