Created
November 1, 2023 21:23
-
-
Save victorbrca/c324fbc6e947ebd091aa4719369fb9a2 to your computer and use it in GitHub Desktop.
YUM update via Ansible
This file contains 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
--- | |
## Tasks file for yum-update | |
# Runs 'yum update' on servers. It can apply full or security only updates, as well as reboot if needed. | |
# Tags: | |
# - full - Performs a full update | |
# - security - Performs security update only | |
# - reboot - Triggers reboot if needed | |
# Security Updates ------------------------------------------------------------- | |
- block: | |
- name: Running YUM security updates | |
yum: | |
name: "*" | |
security: yes | |
state: latest | |
register: yum_output | |
- name: Displays YUM output | |
debug: | |
var: yum_output | |
- name: Checking if reboot is required | |
shell: needs-restarting -r | |
failed_when: false | |
register: reboot_required | |
changed_when: false | |
tags: security | |
# Full Updates ----------------------------------------------------------------- | |
- block: | |
- name: Running YUM updates | |
yum: | |
name: "*" | |
state: latest | |
register: yum_output | |
- name: Displays YUM output | |
debug: | |
var: yum_output | |
- name: Checking if reboot is required | |
shell: needs-restarting -r | |
failed_when: false | |
register: reboot_required | |
changed_when: false | |
tags: full | |
# Reboot ----------------------------------------------------------------------- | |
- when: yum_output.changed == true and reboot_required.rc != 0 | |
block: | |
- name: Rebooting the server | |
shell: shutdown -r now "Ansible Security Updates Triggered" | |
ignore_errors: true | |
changed_when: false | |
async: 1 | |
poll: 0 | |
- name: Waiting for server to come back after reboot | |
wait_for_connection: | |
connect_timeout: 60 | |
sleep: 5 | |
delay: 5 | |
timeout: 300 | |
register: reboot_result | |
- name: Displaying reboot time | |
debug: | |
msg: "The system rebooted in {{ reboot_result.elapsed }} seconds." | |
tags: | |
- reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment