Add APT update playbook
This commit is contained in:
28
apt-update.yml
Normal file
28
apt-update.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- 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
|
||||
Reference in New Issue
Block a user