async fails after running vsphere_guest

169 views
Skip to first unread message

Tim

unread,
Jan 25, 2017, 10:21:42 AM1/25/17
to Ansible Project

I try to run the following tasks like shown below.
 
 - name: add test host (fire and forget)
    vsphere_guest
:
      vcenter_hostname
: srv-vcenter01.ansible.local
      username
: administrator@vsphere.ansible.local
      password
: P@ssw0rd
      guest
: "{{item.hostname}}"
      from_template
: yes
      template_src
: temp-win-2k12-r2
      esxi
:
        datacenter
: Ansible-DC
        hostname
: srv-esx02.ansible.local
      vm_extra_config
:
        folder
: VMs
    with_items
: "{{ serverlist }}"
    async
: 1800
    poll
: 0
   
register: sleeper1

 
- name: check fire and forget
    async_status
:
      jid
: "{{ sleeper1.ansible_job_id }}"
   
register: job_result
   
until: job_result.finished
    retries
: 30

I want to start the set of async tasks and then check their status inside "until" loop.
During the checking ansible fails with error "'dict object' has no attribute 'ansible_job_id'"
Nearly same problem like here


Has anyone an idea?

Stankovic, Marko

unread,
Jan 25, 2017, 10:49:44 AM1/25/17
to ansible...@googlegroups.com
Nearly the same, but you missed the fact that sleeper1 variable contains "result":
"When using register with a loop, the data structure placed in the variable will contain a results attribute that is a list of all responses from the module."
http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop

You need something like
with_items: "{{ sleeper1.results }}"
at the end of "check fire and forget" and {{ item.ansible_job_id }} instead of {{ sleeper1.ansible_job_id }}

Cheers,
Marko


______________________________________________________________________________________________________

CONFIDENTIALITY NOTICE: This message is the property of International Game Technology PLC and/or
its subsidiaries and may contain proprietary, confidential or trade secret information.
This message is intended solely for the use of the addressee. If you are not the intended recipient
and have received this message in error, please delete this message from your system. Any unauthorized
reading, distribution, copying, or other use of this message or its attachments is strictly prohibited.

Tim

unread,
Jan 26, 2017, 2:48:26 AM1/26/17
to Ansible Project
Perfect, that brought me a step further! Still having a problem (check back on fire-and-forget task doesn't do anything when the task is done). But anyways thank you very much Marko!

Regards, Tim
Reply all
Reply to author
Forward
0 new messages