rebooting nodes (centos)

54 views
Skip to first unread message

Trond Hindenes

unread,
Oct 8, 2015, 9:00:33 AM10/8/15
to Ansible Project
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?

Trond Hindenes

unread,
Oct 8, 2015, 9:02:40 AM10/8/15
to Ansible Project
This is the actual error I'm getting:
fatal: [<servername>] => SSH Error: Shared connection to <servername> closed.

David Karban

unread,
Oct 8, 2015, 11:06:25 AM10/8/15
to ansible...@googlegroups.com
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



David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/febef30b-6352-40d6-9143-cb0171036822%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bill Nottingham

unread,
Oct 8, 2015, 11:55:13 AM10/8/15
to ansible...@googlegroups.com
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


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Bill Nottingham
Director of Product, Ansible
ansible.com

Vikas Kumar

unread,
Oct 8, 2015, 12:32:58 PM10/8/15
to Ansible Project
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

Trond Hindenes

unread,
Oct 8, 2015, 2:33:57 PM10/8/15
to Ansible Project
Thanks guys. A shell wait combined with async is probably the way to go. I'll test tomorrow and report back!
Reply all
Reply to author
Forward
0 new messages