For use with eg CentOS.

Assumes you have a file /etc/ansible/hosts with groups and members already configured.

A properly formatted .yml-file can be found at the end of the article.

What this playbook does:

  1. Excludes a member from the group centos-cli.
  2. Doesn't gather facts to speed things up.
  3. Updates all packages to their latest version.
  4. Compares the running kernel version with the latest installed as a hint if a reboot is needed to activate the latest installed kernel version.
  5. Reboots.
  6. Waits till the connection is back.

- hosts: centos-cli:!
gather_facts: no

- name: upgrade all packages
yum: name='*' state=latest
- name: check for reboot hint
shell: if [ $(rpm -q --last kernel | awk 'NR==1 {print $1}') != kernel-$(uname -r) ]; then echo 'reboot'; else echo 'Kernel is current'; fi
ignore_errors: true
register: reboot_hint
- name: Rebooting ...
command: shutdown -r now "Reboot required for updated kernel"
async: 0
poll: 0
ignore_errors: true
changed_when: "reboot_hint.stdout == 'reboot'"
register: rebooting
- name: Wait for computer to reboot...
pause: seconds=60
when: rebooting|changed







Download this file ([]0.7 kB