Skip to content

Instantly share code, notes, and snippets.

@ratzo
Last active May 7, 2020 05:51
Show Gist options
  • Save ratzo/777ffea41bcb617b3adf1276d69fcb84 to your computer and use it in GitHub Desktop.
Save ratzo/777ffea41bcb617b3adf1276d69fcb84 to your computer and use it in GitHub Desktop.
Ansible playbook to upgrade packages on Ubuntu/Debian distributions and reboot the server if needed
---
- hosts: all
become: true
tasks:
- name: Update apt repo and cache
apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
- name: Upgrade all packages
apt:
upgrade: dist
force_apt_get: yes
- name: Check if a reboot is needed
register: reboot_required_file
stat: path=/var/run/reboot-required get_md5=no
- name: Reboot the server if needed
reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 300
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: uptime
when: reboot_required_file.stat.exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment