-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwireguard_client_remove.yml
More file actions
executable file
·55 lines (48 loc) · 1.56 KB
/
wireguard_client_remove.yml
File metadata and controls
executable file
·55 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- hosts: servers
become: yes
gather_facts: yes
vars:
client_name: "{{ client_name }}"
tasks:
- name: Validate client_name variable
assert:
that:
- client_name is defined
- client_name != ''
fail_msg: "The 'client_name' variable must be set. Usage: make vpn-client-remove"
- name: Check if client configuration exists
stat:
path: "/etc/wireguard/{{ client_name }}.conf"
register: client_conf
- name: Fail if client configuration does not exist
fail:
msg: "Client configuration for {{ client_name }} does not exist!"
when: not client_conf.stat.exists
- name: Remove client from WireGuard server configuration
blockinfile:
path: /etc/wireguard/wg0.conf
state: absent
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR {{ client_name }}"
register: removed_from_config
- name: Delete client configuration file
file:
path: "/etc/wireguard/{{ client_name }}.conf"
state: absent
- name: Delete client zip file (cleanup)
file:
path: "/etc/wireguard/{{ client_name }}.zip"
state: absent
# --- Robust Reload ---
- name: Reload WireGuard Configuration
block:
- name: Attempt hot reload (syncconf)
shell: wg syncconf wg0 <(wg-quick strip wg0)
args:
executable: /bin/bash
when: removed_from_config is changed
rescue:
- name: Fallback to hard restart
systemd:
name: wg-quick@wg0
state: restarted