# Trying to use wait\_for to sequence a set of reboots

**URL:** <https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671>\
**Category:** Ansible Project\
**Created:** [October 3, 2017, 3:14pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671 "2017-10-03T15:14:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeamHall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leamhall/32/9390_2.png) [@LeamHall](https://forum.ansible.com/u/LeamHall)\
**Post date:** [October 3, 2017, 3:14pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671/1 "2017-10-03T15:14:31Z")

</div>

Not doing well.

It starts here: [https://github.com/LeamHall/Ansible\_Test/blob/master/playbooks/reboot\_nodes.yml](https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/reboot_nodes.yml)

| 
- hosts: b2532\_vms

 |
|
| |

| 

become: True

 |
|
| |

| |
|
| |

| 

vars:

 |
|
| |

| 

hosts:

 |
|
| |

| 
- genesis

 |
|
| |

| 
- exodus

 |
|
| |

| |
|
| |

| 

roles:

 |
|
| |

- reboot

Which should call playbooks/roles/reboot/tasks/main.yml: [https://github.com/LeamHall/Ansible\_Test/blob/master/playbooks/roles/reboot/tasks/main.yml](https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/roles/reboot/tasks/main.yml)

| 
- name: reboot\_and\_wait\_for

 |
|
| |

| 

include: reboot\_node.yml

 |
|
| |

| 

include: wait\_for.yml

 |
|
| |

| 

include: debug.yml

 |
|
| |

| |
|
| |

| 

with\_items:

 |
|
| |

- "{{ hosts }}"

Which should call: [https://github.com/LeamHall/Ansible\_Test/blob/master/playbooks/roles/reboot/tasks/reboot\_node.yml](https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/roles/reboot/tasks/reboot_node.yml)

| 
- name: reboot

 |
|
| |

command: /sbin/reboot

But doesn’t. It does call the debug.yml file which just says “Hello there!”

Ideas? The goal is to reboot and wait\_for each host in turn.

Leam

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 3, 2017, 3:31pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671/2 "2017-10-03T15:31:25Z")

</div>

You can't have 3 includes in 1 task, you will need to split them into 3 separate tasks.

---

<div class="post-metadata">

**Author:** ![LeamHall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leamhall/32/9390_2.png) [@LeamHall](https://forum.ansible.com/u/LeamHall)\
**Post date:** [October 3, 2017, 3:37pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671/3 "2017-10-03T15:37:06Z")

</div>

Kai, thanks! The issue is that I’m really struggling to get the “wait\_for” to work. I need to have the rebooted machine up before I boot the next one. Any good pointers to docs? Ansible docs say it can be done but don’t seem to show you how.

Leam

---

<div class="post-metadata">

**Author:** ![LeamHall](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/leamhall/32/9390_2.png) [@LeamHall](https://forum.ansible.com/u/LeamHall)\
**Post date:** [October 3, 2017, 4:31pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671/4 "2017-10-03T16:31:15Z")

</div>

This is about the best I have so far. When I tried to put the duplicate tasks into a role it didn’t work. May try an “include\_tasks” after a nap.

[https://github.com/LeamHall/Ansible\_Test/blob/master/playbooks/reboot\_nodes.yml](https://github.com/LeamHall/Ansible_Test/blob/master/playbooks/reboot_nodes.yml)

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [October 3, 2017, 4:48pm UTC](https://forum.ansible.com/t/trying-to-use-wait-for-to-sequence-a-set-of-reboots/25671/5 "2017-10-03T16:48:27Z")

</div>

what I’m using as part of a (multi-hosts) play:

Task one is to async trigger the reboot  
Task two the wait for ssh to come back (for each host in the play)

- name: Reboot the system  
shell: sleep 2 && shutdown -r now “Ansible reboot triggered”  
become: True  
async: 1  
poll: 0  
ignore\_errors: true

# FixMe: Trigger the wait for ssh on all the targets (long operation)

- name: waiting for server to come back  
wait\_for:  
host: “{{ inventory\_hostname }}”  
port: 22  
delay: 15  
timeout: 1200  
connect\_timeout: 15  
state: started  
delegate\_to: localhost
