system reboot and recovery in playbook

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] => {“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

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

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