Skip to content

Instantly share code, notes, and snippets.

@maartenk
Created December 14, 2015 21:07
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 maartenk/c1e6e16e1a3757edd186 to your computer and use it in GitHub Desktop.
Save maartenk/c1e6e16e1a3757edd186 to your computer and use it in GitHub Desktop.
Ansible playbook to update and upgrade machines via apt
# Config retrieved from:
# https://realguess.net/2014/12/21/ansible-update-servers-to-the-latest-and-reboot/
- name: update and upgrade machines via apt
hosts: makr # To change to own hosts / groups
sudo: true
tasks:
- name: Check if there are packages available to be installed/upgraded
command: /usr/lib/update-notifier/apt-check --package-names
register: packages
- name: Upgrade all packages to the latest version
apt: update_cache=yes upgrade=dist
when: packages.stderr != ""
- name: Check if a reboot is required
register: file
stat: path=/var/run/reboot-required get_md5=no
- name: Reboot the server
command: /sbin/reboot
when: file.stat.exists == true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment