reboot via ansible 2.4

Hello Friends,

Does anyone have experience using the reboot playbook on RHEL systems, i’m using below method and it reboots the systems but in between while system is rebooting it breaks the connection and does not wait for post reboot status like uptime, if someone already overcomed this please let me know , my play looks like below…

Hi,

Hello Friends,

Does anyone have experience using the reboot playbook on RHEL systems,
i'm using below method and it reboots the systems but in between while
system is rebooting it breaks the connection and does not wait for
post reboot status like uptime, if someone already overcomed this
please let me know , my play looks like below...

---
- name: Reboot a host and wait for it to return
hosts: postinstall
remote_user: root

tasks:
- name: check automount
service: name=autofs state=stopped

\- name: reboot host
  shell: sleep 10 && /sbin/shutdown \-r now
  async: 360
  poll: 0
  become: true

Without any log of what's the problem exactly is, it's not so obvious to
help you... Did you try to add a sleep just after the shutdown (on the
shell line) like written in this article ?
https://stackoverflow.com/questions/23877781/how-to-wait-for-server-restart-using-ansible

\- name: waiting for server booting up
  local\_action: wait\_for host="\{\{ inventory\_hostname \}\}" port=22

delay=5 timeout=360

\- name: check uptime
  local\_action: shell ansible \-u \{\{ ansible\_user\_id \}\} \-m ping \{\{

inventory_hostname }}
register: result
until: result.rc == 0
retries: 30
delay: 10

Why using shell to do an ansible ping ?
You can use it directly.... Try to always avoid shell module

\# And finally, execute 'uptime' when the host is back\.
\- shell: uptime

There's a fact for this :
ansible_uptime_seconds
Why not using it ?

Regards,

JYL

Thanks JYL, by the way there is no log when i run this play , even system gets rebooted and up but it doesn’t give any clue and breaks the connection .
Anyway, i will try to debug the logs…

You can add more verbose with -v and -vv, etc during execution off your
playbook on the controller site to better understand the problem
There are a minimum of log on the destination site too, do a grep
ansible /var/log/messages and you will have some information

Regards,

JYL

Hello

you wait 10 seconds before calling shutdown but check after 5 seconds whether the port is accessible again.

I use async as well but firstly check via a localaction that the ssh port is drained/not reachable anymore

Best regards
Mirko