vpn-btcpay-provisioner/ansible/playbooks/vpn_cleanup.yml

50 lines
1.5 KiB
YAML
Raw Permalink Normal View History

2024-12-13 09:57:12 +00:00
---
- name: Cleanup expired VPN configuration
hosts: vpn_servers
become: yes
vars:
client_dir: /etc/wireguard/clients
test_client_dir: /etc/wireguard/test_clients
2024-12-13 09:57:12 +00:00
wg_interface: wg0
is_test: false # Default to production mode
2024-12-13 09:57:12 +00:00
tasks:
- name: Debug cleanup information
2024-12-13 09:57:12 +00:00
debug:
msg:
- "Cleaning up subscription ID: {{ subscription_id }}"
- "Test mode: {{ is_test }}"
# Set working directory based on mode
- name: Set working directory based on mode
set_fact:
working_client_dir: "{{ test_client_dir if is_test else client_dir }}"
2024-12-13 09:57:12 +00:00
- name: Remove client configuration directory
file:
path: "{{ working_client_dir }}/{{ subscription_id }}"
2024-12-13 09:57:12 +00:00
state: absent
- name: Remove client from server config
blockinfile:
path: "/etc/wireguard/{{ wg_interface }}.conf"
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR {{ subscription_id }}"
state: absent
notify: restart wireguard
# Remove cleanup cron job if it exists (for test configs)
- name: Remove cleanup cronjob
when: is_test
cron:
name: "cleanup_test_vpn_{{ subscription_id }}"
state: absent
- name: Log cleanup
shell: |
logger -t vpn-cleanup "Cleaned up VPN configuration for {{ subscription_id }} ({{ 'test' if is_test else 'production' }})"
2024-12-13 09:57:12 +00:00
handlers:
- name: restart wireguard
service:
name: "wg-quick@{{ wg_interface }}"
state: restarted