How Do You Get an Ansible Playbook to Issue a Reboot of a Server and Wait for the Server to Come back?

Problem scenario
You know that the orchestrated installation of interconnected systems can have a significant benefit. Sometimes ordering the installation of packages on a single server can be useful. You do not want a "failed to connect to server" or "ansible ssh shared connection failed" message when you run a playbook.  You want the playbook run to wait for the server to boot up again.  The playbook reboots multiple servers at once.  What should you do?

Solution
1.  Change the ansible.cfg file to have this stanza underneath the [ssh] section:

ssh_args = -o ControlMaster=no -o ControlPersist=120s

2.  Use the "serial: 1" attribute above the "shell: sleep 3 && shutdown -r" command.  This way the servers reboot serially.  Ansible seems to perform more reliably when the managed nodes reboot this way.

# This solution was adapted from this posting.

Leave a comment

Your email address will not be published. Required fields are marked *