Ansible: Update Servers to the Latest and Reboot
This is for Debian/Ubuntu flavored systems.
Keep a single server up to date is easy, but updating multiple servers at once, you need tools like Ansible. For each server, here is a list of basic steps:
- Check if there are packages available to be upgraded
- Upgrade all packages to the latest version
- Check if a reboot is required
- Reboot the server
When we log into the remote server, we might see the message showing the number of packages can be updated. The message is generated by:
And it is available at:
We don’t need that detailed information, we just simply want to know if there are update available.
/usr/lib/update-notifier/apt-check shows any pending updates:
To list all the packages instead of simple
--package-names option will write data to
stderr instead of
stdout. If there are no packages needed to be installed, then the
stderr should be empty.
If there are packages to be installed or upgraded. Ansible has the apt module to manage them in Debian/Ubuntu based systems.