diff --git a/apt-update.yml b/apt-update.yml new file mode 100644 index 0000000..41f2a00 --- /dev/null +++ b/apt-update.yml @@ -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