Ansible: check async_status on multiple jobs with and without results

Viewed 55

I have three Ansible tasks for downloading various resources. Two of them are created using a loop, so, they have the key results and return lists of objects and one returns just one object that has the key ansible_job_id.

How can I iterate over all of them in one check job statuses task? I've tried with_nested but got the error

'list object' has no attribute 'ansible_job_id'

- name: Check download job statuses
  async_status:
    jid: "{{ item.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 12
  delay: 10
  with_nested:
    - list1.results
    - list2.results
    - object
1 Answers

You just have to make one list with all the elements having the ansible_job_id key.

Concatenation of lists is as simple, in Jinja, as adding them — with the + operator.
So, your task ends up being:

- name: Check download job statuses
  async_status:
    jid: "{{ item.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 12
  delay: 10
  loop: "{{ list1.results + list2.results + [object] }}"
Related