Harsha S Adiga
Harsha S Adiga

Reputation: 11

Ansible async module with poll=0 doesn't finish the task

First of all, I'm using Ansible 2.0.0 (which I can't avoid).

I've a task like this. Here I'm using ping command to send traffic to a destination machine for 2 minutes. This command runs on a remote machine.

- name: Ping destination VM from host VM.
  shell: ping -n -i 0.004 100.1.1.1 -c 30000 | grep "received" | cut -d"," -f2 | xargs | cut -d" " -f1
  delegate_to: 172.25.11.207
  async: 250
  poll: 0
  register: ping_result
  failed_when: ping_result.rc != 0

I've 2-3 other tasks after this. That should not take more than a minute.

Now, after these tasks, I want to capture the output of ping_result. So I check the status of the above task like below:

- name: Check ping status
  async_status:
    jid: "{{ ping_result.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 10

Now this fails with the below error:

FAILED! => {"failed": true, "msg": "ERROR! The conditional check 'job_result.finished' failed. The error was: ERROR! error while evaluating conditional (job_result.finished): ERROR! 'dict object' has no attribute 'finished'"}

From the error, it looks like the original task has not finished. I even tried to increase the async time, say till 5000. No luck.

Any help on this would be appreciated.

Upvotes: 1

Views: 2854

Answers (2)

Lahiru Chandima
Lahiru Chandima

Reputation: 24108

Following worked for me

until: job_result.finished is defined and job_result.finished

Upvotes: 0

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68289

Answer from the comment:

You should use delegate_to to check status of async job, because original async task has been delegated as well.

Upvotes: 2

Related Questions