# rebooting nodes (centos)

**URL:** <https://forum.ansible.com/t/rebooting-nodes-centos/19463>\
**Category:** Ansible Project\
**Created:** [October 8, 2015, 1:00pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463 "2015-10-08T13:00:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [October 8, 2015, 1:00pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/1 "2015-10-08T13:00:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [October 8, 2015, 1:02pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/2 "2015-10-08T13:02:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [October 8, 2015, 3:05pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/3 "2015-10-08T15:05:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bill\_Nottingham](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@Bill\_Nottingham](https://forum.ansible.com/u/Bill_Nottingham)\
**Post date:** [October 8, 2015, 3:55pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/4 "2015-10-08T15:55:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vikas\_Kumar](https://avatars.discourse-cdn.com/v4/letter/v/ecb155/32.png) [@Vikas\_Kumar](https://forum.ansible.com/u/Vikas_Kumar)\
**Post date:** [October 8, 2015, 4:32pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/5 "2015-10-08T16:32:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trond\_Hindenes](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@Trond\_Hindenes](https://forum.ansible.com/u/Trond_Hindenes)\
**Post date:** [October 8, 2015, 6:33pm UTC](https://forum.ansible.com/t/rebooting-nodes-centos/19463/6 "2015-10-08T18:33:57Z")

</div>

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