Upgrades and reboots - question

78 views
Skip to first unread message

Patrick Galbraith

unread,
Nov 9, 2014, 9:33:55 PM11/9/14
to ansible...@googlegroups.com
Hi all!

We've been working on a playbook that does a dist upgrade and then performs a reboot. This has been problematic and results in a failure return status that sometimes means it worked and sometimes not. What is the trick to reboots -- being able to smoothly reconnect after a reboot signal?

---
- name: reboot the server
  command: shutdown -r now "Ansible updates triggered"
  async: 0
  poll: 0
  ignore_errors: true
  tags:
    - reboot

- name: waiting for server to come back
  sudo: false
  local_action: >
    wait_for:
      host: {{ inventory_hostname }}
      timeout: 300
      delay: 0
      port: 22
      state: started
  tags:
    - reboot

Is there a technique that is commonly used that results in better plays that result in success?

Regards,

Patrick 

J Hawkesworth

unread,
Nov 10, 2014, 5:14:50 AM11/10/14
to ansible...@googlegroups.com
Just a guess but you might want to have a few seconds of delay set in your wait_for so that there is time for network services and sshd to come back up before ansible goes looking for it.

Azul Inho

unread,
Nov 11, 2014, 6:30:18 AM11/11/14
to ansible...@googlegroups.com

This works on my machine,

- name: wait for server to come back
  local_action: shell while true; do echo "Waiting ..." ; ssh -o ConnectTimeout=5 -o BatchMode=yes  {{ inventory_hostname }} pwd ; [ $? -eq 0 ] && break || sleep 5; done
  sudo: false
 

John Batty

unread,
Nov 14, 2014, 9:15:50 AM11/14/14
to ansible...@googlegroups.com
Your server may still be in the process of shutting down when your "wait_for" is executed.  So the wait_for could make a connection and think the server is back up when it is actually on its way down...

Try setting the delay parameter in the wait_for (e.g to 15) to ensure that the server is down/rebooting before waif_for starts checking.

John
Reply all
Reply to author
Forward
0 new messages