From b1d691ecdfcfc8f64891bc761d35822c75b907af Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Sat, 19 Jul 2025 17:46:35 -0400 Subject: [PATCH] Added some maintenance scripts --- playbooks/maintenance/clean-proxies.yml | 35 +++++++++++++++++++++ playbooks/maintenance/disk-usage-report.yml | 13 ++++++++ 2 files changed, 48 insertions(+) create mode 100644 playbooks/maintenance/clean-proxies.yml create mode 100644 playbooks/maintenance/disk-usage-report.yml diff --git a/playbooks/maintenance/clean-proxies.yml b/playbooks/maintenance/clean-proxies.yml new file mode 100644 index 0000000..0c8e652 --- /dev/null +++ b/playbooks/maintenance/clean-proxies.yml @@ -0,0 +1,35 @@ +--- +- name: Clean proxy VMs of left over build files and packages + hosts: proxies + become: true + tasks: + - name: Check Caddy binary location + ansible.builtin.command: which caddy + register: caddy_path + + - name: Fail if Caddy is running from /root/go + ansible.builtin.fail: + msg: "Caddy is running from /root/go — aborting cleanup to avoid breaking it." + when: caddy_path.stdout.startswith('/root/go') + + - name: Ensure go is installed (to use go clean) + ansible.builtin.command: which go + register: go_check + failed_when: go_check.rc != 0 + changed_when: false + + - name: Clean Go module and build cache + ansible.builtin.command: go clean -modcache -cache -testcache + environment: + HOME: /root + when: go_check.rc == 0 + + - name: Remove /root/go + ansible.builtin.file: + path: /root/go + state: absent + + - name: Remove /root/.cache + ansible.builtin.file: + path: /root/.cache + state: absent \ No newline at end of file diff --git a/playbooks/maintenance/disk-usage-report.yml b/playbooks/maintenance/disk-usage-report.yml new file mode 100644 index 0000000..d097650 --- /dev/null +++ b/playbooks/maintenance/disk-usage-report.yml @@ -0,0 +1,13 @@ +--- +- name: Check disk usage across all nodes + hosts: vms + become: true + gather_facts: false + tasks: + - name: Get disk usage of root filesystem + ansible.builtin.shell: du -h -d1 --one-file-system / | sort -hr + register: disk_usage + + - name: Print disk usage for {{ inventory_hostname }} + ansible.builtin.debug: + msg: "{{ inventory_hostname }} → {{ disk_usage.stdout_lines | join('\n') }}"