Skip to content

Commit 0fbb4f9

Browse files
Ryan Williamsclaude
andcommitted
Fix AWX job status validation to check actual job result
The previous fix in PR #402 was checking steps.awx_job.outcome, which only validates that the fitbeard/action-trigger-awx action itself ran successfully. However, the action always exits with success even when the AWX job fails, because it only exits non-zero during its own validation steps, not based on the Ansible playbook execution result. This fix now: 1. Checks if the action step itself succeeded (steps.awx_job.outcome) 2. Retrieves the job_id output from the action 3. Queries the AWX API directly to check the actual job status 4. Fails the workflow if the job status is "failed" or if the failed flag is true 5. Fails if the status is anything other than "successful" This ensures that AWX/Ansible failures (SOPS errors, unreachable hosts, task failures, etc.) properly fail the GitHub Actions workflow. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6590200 commit 0fbb4f9

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

.github/actions/ansible/action.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,42 @@ runs:
7777
if: always()
7878
shell: bash
7979
run: |
80-
# Check if the AWX job step succeeded
80+
# First check if the AWX action step itself failed
8181
if [[ "${{ steps.awx_job.outcome }}" != "success" ]]; then
82-
echo "::error::AWX job failed or was cancelled"
82+
echo "::error::AWX action step failed or was cancelled"
8383
exit 1
8484
fi
8585
86+
# Now check the actual AWX job status using the job ID
87+
JOB_ID="${{ steps.awx_job.outputs.job_id }}"
88+
89+
if [[ -z "$JOB_ID" ]]; then
90+
echo "::error::No job ID returned from AWX"
91+
exit 1
92+
fi
93+
94+
echo "Checking status of AWX job $JOB_ID"
95+
96+
# Query AWX API for job status
97+
RESPONSE=$(curl -s -k -H "Authorization: Bearer ${{ env.AWX_OAUTH_TOKEN }}" \
98+
"${{ env.AWX_HOST }}/api/v2/jobs/$JOB_ID/")
99+
100+
STATUS=$(echo "$RESPONSE" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
101+
FAILED=$(echo "$RESPONSE" | grep -o '"failed":[^,}]*' | cut -d':' -f2)
102+
103+
echo "Job status: $STATUS"
104+
echo "Failed flag: $FAILED"
105+
106+
# Check if job failed
107+
if [[ "$STATUS" == "failed" ]] || [[ "$FAILED" == "true" ]]; then
108+
echo "::error::AWX job $JOB_ID failed"
109+
exit 1
110+
fi
111+
112+
if [[ "$STATUS" != "successful" ]]; then
113+
echo "::error::AWX job $JOB_ID did not complete successfully (status: $STATUS)"
114+
exit 1
115+
fi
116+
117+
echo "AWX job $JOB_ID completed successfully"
118+

0 commit comments

Comments
 (0)