Using Ansible 1.7, I am executing multiple asynchronous tasks in a loop, and checking on their status with async_status with a 30-second timeout:
- name: Some long-running task
shell: "./some_task {{ item }}"
loop: "{{ list_of_params }}"
async: 30
poll: 0
register: my_task
- name: Check async tasks for completion
async_status:
jid: "{{ item.ansible_job_id }}"
register: my_task_results
until: my_task_results.finished
retries: 30
delay: 1
loop: "{{ my_task.results }}"
This works well, and the async_status task fails if any of the shell commands return non-zero return-code, or if "my_task_results.finished" is not true within 30 seconds.
Unfortunately, the error message is not helpful when the "until" condition is not met in time. The returned values include:
- changed: false
- msg: "All items completed"
- results: [ array of results from shell task above ]
- changed: false
- failed: true
- finished: 0
Particularly, the "All items completed" message is misleading.
Is there a way to produce a meaningful error message in this case? I can add a "failed_when" option, with an additional "Fail" task to check condition (finished == 0) to display a custom error message (Something to the effect of "Some long-running task did not complete in time"), but this seems inelegant.