Last active
March 27, 2022 14:26
-
-
Save h0tw1r3/e577654ebf0e690d7b84c7edf4e6fcd8 to your computer and use it in GitHub Desktop.
ansible playbook to update all apt or yum packages
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 | |
tasks: | |
- name: "yum: upgrade packages" | |
yum: | |
name: '*' | |
state: latest | |
update_cache: yes | |
update_only: yes | |
register: yum_update_status | |
when: ansible_facts.pkg_mgr == 'dnf' or ansible_facts.pkg_mgr == 'yum' | |
- name: "yum: remove automatically installed packages without dependencies" | |
yum: | |
autoremove: yes | |
when: ansible_facts.pkg_mgr == 'dnf' or ansible_facts.pkg_mgr == 'yum' | |
- name: "apt: upgrade installed packages" | |
apt: | |
name: '*' | |
state: latest | |
update_cache: yes | |
only_upgrade: yes | |
register: apt_update_status | |
when: ansible_facts.pkg_mgr == 'apt' | |
- name: "apt: remove automatically installed packages without dependencies" | |
apt: | |
autoremove: yes | |
when: ansible_facts.pkg_mgr == 'apt' | |
- name: reboot if packages were updated | |
reboot: | |
post_reboot_delay: 60 | |
when: (apt_update_status.changed or yum_update_status.changed) and update_reboot |
Author
h0tw1r3
commented
Mar 27, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment