how to get the ansible virt module to wait for a machine to finish shutting down

1,328 views
Skip to first unread message

Rob Verduijn

unread,
Apr 4, 2016, 9:05:15 AM4/4/16
to Ansible Project
Hello,

When shutting down a kvm guest using the task
- name: shut down kvm guest
  virt: name=kvm-guest state=shutdown

Ansible will continue when the virsh shutdown kvm-guest command is finished.

However I want it to wait for the guest to actually finnish the shutdown procedure.

Anybody who knows how to do this ?

Rob Verduijn

Nitin Mathur

unread,
Oct 27, 2016, 3:11:27 PM10/27/16
to Ansible Project
Were you able to figure this out? Or any suggestions??

Kai Stian Olstad

unread,
Oct 27, 2016, 4:49:50 PM10/27/16
to ansible...@googlegroups.com
On 27. okt. 2016 21:05, Nitin Mathur wrote:
> On Monday, April 4, 2016 at 6:05:15 AM UTC-7, Rob Verduijn wrote:
>>
>> Hello,
>>
>> When shutting down a kvm guest using the task
>> - name: shut down kvm guest
>> virt: name=kvm-guest state=shutdown
>>
>> Ansible will continue when the virsh shutdown kvm-guest command is
>> finished.
>>
>> However I want it to wait for the guest to actually finnish the shutdown
>> procedure.
>>
>> Anybody who knows how to do this ?
>
> Were you able to figure this out? Or any suggestions??

You can use a do until loop
https://docs.ansible.com/ansible/playbooks_loops.html#do-until-loops

- action: virt name=kvm-guest command=status
register: result
until: result.status.find("shutdown") != -1
retries: 30
delay: 5


--
Kai Stian Olstad

Patrick Laimbock

unread,
Oct 27, 2016, 5:51:08 PM10/27/16
to ansible...@googlegroups.com
Hi,

Here's a snippet that I use:

- name: wait for the vm to shut down
virt:
command: status
name: "{{ inventory_hostname }}"
register: vmstatus
until: vmstatus.status == 'shutdown'
delegate_to: "{{ vmhost }}"
retries: 1500
delay: 10

vmhost = the hypervisor on which the VM runs.

HTH,
Patrick
> --
> You received this message because you are subscribed to the Google
> Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ansible-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a6045c13-303b-4adc-b718-d62afde3b523%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a6045c13-303b-4adc-b718-d62afde3b523%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages