Search code examples
ansibleansible-awxansible-tower

Custom Job Status for AWX/Ansible Tower workflows


AWX/Ansible Tower has it's own REST API service. From the below URL structure I can get information about an in progress or finished workflow job:

https://<awx-ip>/api/v2/workflow_jobs/<job-id>/

But the status field at this URL doesn't show the value I desire. If the templates that run in this job didn't get an error during execution, the value always shows a successful.

So, I need a way to show my desired job status by this REST API service. Maybe below field can be edited, but i don't know how:

"job_explanation": ""

I only need a field to serve a custom status about the ongoing or completed job. For example partial, failed, successful, ongoing etc.

How can I edit or add a field during the ongoing job and after it is completed. Is there a way to manipulate the fields on rest API's job stats?


Solution

  • According the Ansible Tower API Reference Guide Workflow Jobs, by Retriving a Workflow Job the status: (choice) can have following values

    new: New
    pending: Pending
    waiting: Waiting
    running: Running
    successful: Successful
    failed: Failed
    error: Error
    canceled: Canceled
    

    ... status about the ongoing or completed job

    So the status should be already there.

    For example partial, failed, successful, ongoing etc.

    So it look like the options you are looking for are already there

    • ongoing -> running
    • partial -> canceled
    • failed -> failed
    • successful -> successful
    curl --silent -u "${ACCOUNT}:${PASSWORD}" https://${TOWER_URL}/api/v2/workflow_jobs/${jobID}/ | jq .
    

    Resulting into an output of

    ...
      "launch_type": "relaunch",
      "status": "running",
      "failed": false,
      "started": "2022-02-04T14:28:04.147633Z",
      "finished": null,
      "canceled_on": null,
      "elapsed": 17.367907,
      "job_args": "",
      "job_cwd": "",
      "job_env": {},
      "job_explanation": "",
    ...
    

    and

    ...
      "launch_type": "relaunch",
      "status": "successful",
      "failed": false,
      "started": "2022-02-04T14:28:04.147633Z",
      "finished": "2022-02-04T14:28:24.156419Z",
      "canceled_on": null,
      "elapsed": 20.009,
      "job_args": "",
      "job_cwd": "",
      "job_env": {},
      "job_explanation": "",
    ...
    

    Maybe below field can be edited, but i don't know how: "job_explanation": ""

    According List Jobs the field

    job_explanation: A status field to indicate the state of the job if it wasn’t able to run and capture stdout (string)

    therefore it should probably not be edited.

    How can I edit or add a field during the ongoing job ...

    The REST API is for creating, starting, stopping and so on of jobs, to remote control the Tower application. The values become set by the application, there is no safe option to set them by yourself via the API.

    ... and after it is completed. Is there a way to manipulate the fields on REST API job stats?

    It might be possible to to alter the job result directly within in PostgreSQL application database backend.

    Also it might be possible for you the change the application ansible/awx/ and the behavior of awx/api/urls/workflow_job.py.