Skip to content

Instantly share code, notes, and snippets.

@fia5000
Forked from edrzmr/ansible-reboot.yaml
Created October 9, 2016 21:56
Show Gist options
  • Save fia5000/3ab3b25eeefb3df5444be9240e89caa7 to your computer and use it in GitHub Desktop.
Save fia5000/3ab3b25eeefb3df5444be9240e89caa7 to your computer and use it in GitHub Desktop.
ansible waiting for reboot, really really works!
- name: 'check if reboot is required'
shell: if [ $(readlink -f /vmlinuz) != /boot/vmlinuz-$(uname -r) ]; then echo 'yes'; else echo 'no'; fi
ignore_errors: true
register: reboot
- name: 'reboot...'
shell: nohup bash -c 'sleep 2 && shutdown -r now "Ansible kernel update applied"' &
async: 0
poll: 0
ignore_errors: true
when: reboot.stdout.find('yes') != -1
register: rebooting
- name: 'waiting...'
local_action: wait_for host={{ ansible_host | default(inventory_hostname,boolean=True) }} search_regex='OpenSSH' port=22 state='started' delay=30 timeout=300
become: no
when: rebooting|changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment