Working ansible command/task for restarting nodes

I didn’t find any working ansible commands to do something on a node, then reboot it, wait for it to come back and do other stuff, so I experimented around and wrote a working
You’ll probably run into trouble when your SSH port is not 22. I guess you can write something with jinja2 syntax to get the SSH port from ansible.
It probably will not work at all, if your SSH port is defined in an ssh_config file (Read the man page for that name, if you don’t know what it is, if you’re interested) and not the ansible hosts list.

I tested this on Ansible and it works here.

So there you go:

 -  name: do something
 -  name: restart node
    shell: sleep 2 && shutdown -r now "Ansible update triggered"
    async: 1
    poll: 0
    ignore_errors: true
    become: true

 -  name: wait for node to come back
        module: wait_for 
            host={{ inventory_hostname }}
    become: false

 -  name: do something


Kind regards,

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.