Skip to content

Instantly share code, notes, and snippets.

@nccurry
Created March 10, 2019 16:10
Show Gist options
  • Save nccurry/8a3a8edb53b70d8527ba569dbc7d668e to your computer and use it in GitHub Desktop.
Save nccurry/8a3a8edb53b70d8527ba569dbc7d668e to your computer and use it in GitHub Desktop.
Reboot ansible host after package update
- name: Update/reboot host
gather_facts: false
become: true
tasks:
- name: Update system packages
yum:
name: '*'
state: latest
register: yum_update
retries: 5
delay: 1
until: yum_update.rc == 0
- name: Reboot server on update
block:
- name: Reboot server
shell: sleep 10 && /sbin/shutdown -r now "System packages updated"
async: 300
poll: 0
become: true
- name: Wait for system to reboot
wait_for_connection:
connect_timeout: 20
sleep: 5
delay: 20
timeout: 300
when: yum_update.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment