From b050d4d2f945c7738686fafc0930b41aeacd4585 Mon Sep 17 00:00:00 2001 From: Wendell Jones Date: Wed, 10 Sep 2025 08:36:50 -0400 Subject: [PATCH] refactor: add update and upgrade tasks for package management in apk, apt, ipk, and rpm YAML files --- apk_updates.yaml | 10 ++++++++ apt_updates.yaml | 27 +++++++++++++++++++++ ipk_updates.yaml | 4 +++ rpm_updates.yaml | 27 +++++++++++++++++++++ linux_updates.yaml => updates_template.yaml | 0 5 files changed, 68 insertions(+) create mode 100644 apk_updates.yaml create mode 100644 apt_updates.yaml create mode 100644 ipk_updates.yaml create mode 100644 rpm_updates.yaml rename linux_updates.yaml => updates_template.yaml (100%) diff --git a/apk_updates.yaml b/apk_updates.yaml new file mode 100644 index 0000000..f57049e --- /dev/null +++ b/apk_updates.yaml @@ -0,0 +1,10 @@ +--- +- hosts: apkhosts + tasks: + - name: Update the Package Repositories + apk: + update_cache: yes + - name: Upgrade Packages + apk: + available: yes + upgrade: yes \ No newline at end of file diff --git a/apt_updates.yaml b/apt_updates.yaml new file mode 100644 index 0000000..7b163bc --- /dev/null +++ b/apt_updates.yaml @@ -0,0 +1,27 @@ +--- +- hosts: debianhosts + gather_facts: no + tasks: + - name: Update apt package cache + ansible.builtin.apt: + update_cache: yes + cache_valid_time: 3600 # Update cache if it's older than 1 hour (3600 seconds) + + - name: Upgrade all packages to the latest version + ansible.builtin.apt: + upgrade: dist # Equivalent to apt-get dist-upgrade + force_apt_get: yes # Ensure apt-get is used instead of aptitud + + - name: Clean up unused dependencies + ansible.builtin.apt: + autoremove: yes + + - name: Check if a file exists + ansible.builtin.stat: + path: /var/run/reboot-required + register: reboot_required_file + + - name: Reboot if required + ansible.builtin.reboot: + reboot_timeout: 120 # Adjust timeout as needed + when: reboot_required_file.stat.exists \ No newline at end of file diff --git a/ipk_updates.yaml b/ipk_updates.yaml new file mode 100644 index 0000000..3f622eb --- /dev/null +++ b/ipk_updates.yaml @@ -0,0 +1,4 @@ +- hosts: ipkg + tasks: + - name: Update the Packages installed on Diskstation + command: /opt/bin/ipkg update && /opt/bin/ipkg upgrade \ No newline at end of file diff --git a/rpm_updates.yaml b/rpm_updates.yaml new file mode 100644 index 0000000..2b7828c --- /dev/null +++ b/rpm_updates.yaml @@ -0,0 +1,27 @@ +--- +- hosts: yumhosts + gather_facts: no + tasks: + - name: Update all installed packages using YUM module + ansible.builtin.yum: + use_backend: yum3 + name: '*' + state: latest + update_cache: yes + update_only: yes + register: yum_update_status + + - name: Remove packages not needed anymore + ansible.builtin.yum: + use_backend: yum3 + autoremove: yes + + - name: Check if a file exists + ansible.builtin.stat: + path: /var/run/needs-restarting + register: reboot_required_file + + - name: Reboot if required + ansible.builtin.reboot: + reboot_timeout: 120 # Adjust timeout as needed + when: reboot_required_file.stat.exists \ No newline at end of file diff --git a/linux_updates.yaml b/updates_template.yaml similarity index 100% rename from linux_updates.yaml rename to updates_template.yaml