29 lines
960 B
YAML
29 lines
960 B
YAML
---
|
|
- name: APT Update Playbook
|
|
hosts: all
|
|
become: yes
|
|
gather_facts: yes
|
|
|
|
tasks:
|
|
- name: Update apt package cache
|
|
ansible.builtin.apt:
|
|
update_cache: yes
|
|
cache_valid_time: 3600
|
|
register: apt_update_result
|
|
when: ansible_os_family == "Debian"
|
|
|
|
- name: Display update result for Debian/Ubuntu systems
|
|
ansible.builtin.debug:
|
|
msg: "APT cache updated successfully on {{ inventory_hostname }}"
|
|
when: ansible_os_family == "Debian" and apt_update_result is succeeded
|
|
|
|
- name: Skip non-Debian systems
|
|
ansible.builtin.debug:
|
|
msg: "Skipping {{ inventory_hostname }} - not a Debian/Ubuntu system ({{ ansible_os_family }})"
|
|
when: ansible_os_family != "Debian"
|
|
|
|
- name: Display failure message
|
|
ansible.builtin.debug:
|
|
msg: "APT update failed on {{ inventory_hostname }}"
|
|
when: ansible_os_family == "Debian" and apt_update_result is failed
|