system reboot and recovery in playbook

107 views
Skip to first unread message

Jamie Duncan

unread,
Feb 10, 2016, 10:06:29 AM2/10/16
to Ansible Project
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



Brian Coca

unread,
Feb 10, 2016, 11:48:52 AM2/10/16
to ansible...@googlegroups.com
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


Jamie Duncan

unread,
Feb 10, 2016, 12:02:48 PM2/10/16
to Ansible Project
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


Reply all
Reply to author
Forward
0 new messages