reboot via ansible 2.4

222 views
Skip to first unread message

rrak...@gmail.com

unread,
Mar 15, 2018, 10:21:32 AM3/15/18
to Ansible Project
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

    - 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

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

Jean-Yves LENHOF

unread,
Mar 15, 2018, 11:33:45 AM3/15/18
to ansible...@googlegroups.com
Hi,


Le 15/03/2018 à 15:21, rrak...@gmail.com a écrit :
> 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

rrak...@gmail.com

unread,
Mar 15, 2018, 12:06:06 PM3/15/18
to Ansible Project
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..

Jean-Yves LENHOF

unread,
Mar 15, 2018, 12:11:39 PM3/15/18
to ansible...@googlegroups.com


Le 15/03/2018 à 17:06, rrak...@gmail.com a écrit :
> 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

Mirko Friedenhagen

unread,
Mar 19, 2018, 1:19:09 AM3/19/18
to ansible-project
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
--
Sent from my mobile

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ae6d87f1-5439-4f66-b4c7-d10e1057ff72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages