Files
ansible/playbooks/update_system.yml
T

50 lines
1.3 KiB
YAML

- name: Check Host Availability
hosts: all
gather_facts: false
tasks:
- name: Ping hosts to check availability
ansible.builtin.ping:
register: ping_result
ignore_errors: true
- name: Add reachable hosts to group
ansible.builtin.group_by:
key: reachable_hosts
when: ping_result is succeeded
- name: Report offline hosts
ansible.builtin.debug:
msg: "Host {{ inventory_hostname }} is OFFLINE and will be skipped"
when: ping_result is failed
- name: Update and Upgrade Packages
hosts: reachable_hosts
become: true
gather_facts: true
tasks:
- name: Update & Upgrade - Debian-based systems
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
upgrade: dist
when: ansible_os_family == "Debian"
- name: Update & Upgrade - Modern RHEL-based systems (DNF)
ansible.builtin.dnf:
name: "*"
state: latest
update_cache: true
when:
- ansible_os_family == "RedHat"
- ansible_pkg_mgr == "dnf"
- name: Update & Upgrade - Legacy RHEL-based systems (YUM)
ansible.builtin.yum:
name: "*"
state: latest
update_cache: true
when:
- ansible_os_family == "RedHat"
- ansible_pkg_mgr == "yum"