Skip to content

Instantly share code, notes, and snippets.

@adaiguoguo
Created September 20, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adaiguoguo/0ac04cbf495e98ee47bfbbcb640febbb to your computer and use it in GitHub Desktop.
Save adaiguoguo/0ac04cbf495e98ee47bfbbcb640febbb to your computer and use it in GitHub Desktop.
ansible-upgrade-kernel
- name: Check for reboot hint.
shell: LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1);CURRENT_KERNEL=$(uname -r); if [ $LAST_KERNEL != $CURRENT_KERNEL ]; then echo 'reboot'; else echo 'no'; fi
ignore_errors: true
register: reboot_hint
- name: Rebooting ...
shell: sleep 2 && /usr/sbin/reboot
async: 1
poll: 0
ignore_errors: true
when: reboot_hint.stdout.find("reboot") != -1
- name: Wait for host to boot
become: false
local_action: wait_for
args:
host: "{{ inventory_hostname }}"
port: 22
state: started
delay: 30
timeout: 180
when: reboot_hint.stdout.find("reboot") != -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment