# system reboot and recovery in playbook

**URL:** <https://forum.ansible.com/t/system-reboot-and-recovery-in-playbook/20513>\
**Category:** Ansible Project\
**Tags:** fedora, kubernetes\
**Created:** [February 10, 2016, 3:05pm UTC](https://forum.ansible.com/t/system-reboot-and-recovery-in-playbook/20513 "2016-02-10T15:05:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamie\_Duncan](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jamie\_Duncan](https://forum.ansible.com/u/Jamie_Duncan)\
**Post date:** [February 10, 2016, 3:05pm UTC](https://forum.ansible.com/t/system-reboot-and-recovery-in-playbook/20513/1 "2016-02-10T15:05:08Z")

</div>

I’m using a blog post I found [0] to set up a reboot and recovery for a playbook that deploys kubernetes across a handful of atomic hosts. It’s simplistic and mostly for my learning experience.

The playbook snippet i’m using.

- hosts: all  
remote\_user: root  
tasks:
- name: reboot all servers  
command: sleep 2 && systemctl reboot  
async: 1  
poll: 0  
ignore\_errors: true
- name: waiting for server to come back  
local\_action: wait\_for host={{ inventory\_hostname }} state=started delay=30 timeout=300 port=22  
sudo: false

It goes through fine, but doesn’t actually reboot the systems.

If i set ‘async: 0’ and run it, i get the following error for each host:

failed: [[kube0.example.com](http://kube0.example.com)] =\> {“changed”: true, “cmd”: [“sleep”, “2”, “&&”, “systemctl”, “reboot”], “delta”: “0:00:00.002212”, “end”: “2016-02-10 09:58:09.760378”, “rc”: 1, “start”: “2016-02-10 09:58:09.758166”, “warnings”: }  
stderr: sleep: invalid time interval ‘&&’  
sleep: invalid time interval ‘systemctl’  
sleep: invalid time interval ‘reboot’  
Try ‘sleep --help’ for more information.

I’m running the playbook on Fedora 23 with ansible 1.9.4

jduncan@dhcp-192-168-1-140 ansible\_deploy$ cat /etc/fedora-release  
Fedora release 23 (Twenty Three)  
jduncan@dhcp-192-168-1-140 ansible\_deploy$ rpm -qa ansible  
ansible-1.9.4-1.fc23.noarch

I don’t quite get how’s it’s passing that into a shell and the shell is mis-interpreting it. Can someone point me in the right direction?

thanks!

jduncan

0 - [https://support.ansible.com/hc/en-us/articles/201958037-Reboot-a-server-and-wait-for-it-to-come-back](https://support.ansible.com/hc/en-us/articles/201958037-Reboot-a-server-and-wait-for-it-to-come-back)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 10, 2016, 4:48pm UTC](https://forum.ansible.com/t/system-reboot-and-recovery-in-playbook/20513/2 "2016-02-10T16:48:45Z")

</div>

when using && you need shell: as command module does not allow for ‘shellisms’

also you want to sleep AFTER the reboot request:

shell: systemctl reboot && sleep 2

---

<div class="post-metadata">

**Author:** ![Jamie\_Duncan](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jamie\_Duncan](https://forum.ansible.com/u/Jamie_Duncan)\
**Post date:** [February 10, 2016, 5:02pm UTC](https://forum.ansible.com/t/system-reboot-and-recovery-in-playbook/20513/3 "2016-02-10T17:02:48Z")

</div>

thanks. the following works cleanly on the above version:

- name: reboot each box  
shell: sleep 2 && systemctl reboot  
async: 1  
poll: 0  
ignore\_errors: true
- name: wait for server to come back  
local\_action: wait\_for host={{ inventory\_hostname }} state=started delay=30 timeout=300 port=22  
sudo: false
