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 foo.uu.se 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.

 

yum.update.with.reboot.as.needed.yml

---
- hosts: centos-cli:!foo.uu.se
gather_facts: no
tasks:

- 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
...

 

 

 

 

 

 

Stop Spam Harvesters, Join Project Honey Pot

 

Get a free SSL certificate!

 

The leading nonprofit defending digital privacy, free speech, and innovation.

 

The Linux Foundation provides a neutral, trusted hub for developers and organizations to code, manage, and scale open technology projects and ecosystems.

 

Kubuntu is an operating system built by a worldwide community of developers, testers, supporters and translators.

 

 43ef5c89 CanonicalUbuntudarktext