rebooting nodes (centos)

Hi all,
As part of a playbook I reboot nodes if they’re missing a file I’m checking against. This is done like so:

  • name: Reboot node if check file does not exist (we assume this is the first run)
    command: shutdown -r now “Ansible updates triggered”
    when: reboot_check_file.stat.exists == False
    async: 0
    poll: 0
    ignore_errors: true

However, whatever I do I always get a “exception: SSH Error: Shared connection to app10002 closed”. How can I force ansible to continue running although it lost its connection?

This is the actual error I’m getting:
fatal: [] => SSH Error: Shared connection to closed.

Hi, are you using wait_for?

  • name: Reboot
    command: shutdown -r now

  • name: Wait until ssh is available again
    local_action: wait_for port=22 host={{ inventory_hostname }} search_regex=OpenSSH delay=10

When you call ‘shutdown -r now’, that means the task cleanup is going to race against the system shutdown killing the ssh daemon. Even if you’re running it async, you probably want a bit of delay.

Bill

Hi Trond,

I use these tasks to reboot servers. These work fine for CentOS 6 and 7 servers.

  • shell: sleep 5 && shutdown -r “{{ ‘1’ if ansible_distribution_major_version == ‘7’ else ‘now’ }}”
  • local_action: wait_for host={{ ansible_hostname }} port=22 timeout=300 delay=90 state=started

Hope this helps.

Regards,
Vikas

Thanks guys. A shell wait combined with async is probably the way to go. I’ll test tomorrow and report back!