feat(semaphore): add dedicated cleanup playbook

- Explicit playbook for removing old container, systemd services, and quadlets
- Optional semaphore_force_clean variable for data removal
- Safer than tags for destructive operations
This commit is contained in:
Hermes Agent service account
2026-05-28 10:25:56 -05:00
parent dcc7e282c7
commit e9440327aa

View File

@@ -0,0 +1,54 @@
---
- name: Cleanup old Semaphore deployment on figment
hosts: semaphore_server
become: true
vars:
# Set to true to also remove data directories and config
semaphore_force_clean: false
tasks:
- name: Stop and remove old Semaphore container
containers.podman.podman_container:
name: "{{ semaphore_container_name }}"
state: absent
ignore_errors: true
- name: Stop and disable legacy generated systemd service
ansible.builtin.systemd:
name: "container-{{ semaphore_container_name }}.service"
state: stopped
enabled: false
ignore_errors: true
- name: Remove legacy systemd unit file
ansible.builtin.file:
path: "/etc/systemd/system/container-{{ semaphore_container_name }}.service"
state: absent
- name: Remove quadlet files (if any were previously deployed)
ansible.builtin.file:
path: "/etc/containers/systemd/{{ item }}.container"
state: absent
loop:
- "{{ semaphore_container_name }}"
- "{{ semaphore_postgres_container_name }}"
- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: true
- name: Remove data directories (only when semaphore_force_clean=true)
when: semaphore_force_clean | bool
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ semaphore_data_dir }}"
- "{{ semaphore_config_dir }}"
- name: Remove PostgreSQL data volume marker (only when semaphore_force_clean=true)
when: semaphore_force_clean | bool and semaphore_use_postgres | default(false)
ansible.builtin.file:
path: "/var/lib/containers/storage/volumes/{{ semaphore_postgres_volume }}/_data"
state: absent
ignore_errors: true