Last active
May 7, 2020 05:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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