35 lines
1012 B
YAML

---
- 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