I am trying to detect all cancelled jobs in Ansible AWX / Tower by querying the API on a periodic basis. Trying to figure out how to do it. Here is what I have.
- name: Pull Jobs Data
uri:
url: https://ansible2.xrxi.com/api/v2/jobs/?format=json&page=1&page_size=1000
headers:
Content-Type: application/json
Authorization: "Bearer {{ lookup('env', 'TOWER_PASSWORD') }}"
register: jobs_data
- name: Add jobs data to dictionary - Cancelled jobs
set_fact:
list_of_jobs_info: "{{ list_of_jobs_info + [{ 'job_id' : item['id'], 'job_name' : item['name'], 'job_status' : item['status'], 'job_cancel' : item['canceled_on'], 'job_template_id' : item['summary_fields']['job_template']['id'], 'job_template_name' : item['summary_fields']['job_template']['name'] }] }}"
when:
- item['canceled_on'] is defined
- item['summary_fields']['job_template'] is defined
- item['job_status'] == "Failed"
loop: "{{ jobs_data['json']['results'] }}"
register : subset_data
- debug:
var: subset_data
Currently it seems to be failing on item['job_status'] == "Failed"
.