Snippets

AWX snippet: capture failed job evidence before rerun

A short sequence to collect status, variables, affected host and error events before rerunning an AWX job.

25 Jun 2026 awxansibleautomationrunbookguardrailscliincidentoperations

Before rerunning a failed AWX job, capture the minimum evidence needed to decide whether the rerun is safe or may replay a partial action.

bash awx-failed-job-evidence.sh
JOB_ID="12345"

awx jobs get "$JOB_ID" --format json | jq '{id,name,status,failed,started,finished,launch_type,inventory,project,job_template,extra_vars}'

awx job_events list --job "$JOB_ID" --event runner_on_failed --format json | jq '.results[] | {host:.host_name, task:.event_data.task, changed:.event_data.res.changed, stderr:.event_data.res.stderr, msg:.event_data.res.msg}'

awx job_events list --job "$JOB_ID" --event runner_on_ok --format json | jq '.results[] | select(.event_data.res.changed == true) | {host:.host_name, task:.event_data.task, changed:.event_data.res.changed}'

Quick read: if changed tasks happened before the failure, the rerun must be idempotent or manually approved; if the failure hits one host, limit the rerun; if extra_vars change between attempts, create new evidence instead of overwriting the diagnosis.