diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-11-13 22:34:00 +0100 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-11-13 22:34:00 +0100 |
| commit | 2db8a4f137da5e3addddce407ab892314ad6093d (patch) | |
| tree | c191c04752e924f5ea6e3716189ea2c1e87e0067 /roles/wireguard | |
| parent | 16b43088143541b91bfb05e64d2dee07189aeb0f (diff) | |
Minor fixes to autostart connection validation/service logic
Diffstat (limited to 'roles/wireguard')
| -rw-r--r-- | roles/wireguard/tasks/main.yml | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/roles/wireguard/tasks/main.yml b/roles/wireguard/tasks/main.yml index 9a69f0d9..b781f114 100644 --- a/roles/wireguard/tasks/main.yml +++ b/roles/wireguard/tasks/main.yml @@ -41,16 +41,25 @@ loop: "{{ wireguard_connections.keys() }}" when: wireguard_connections | length > 0 +- name: "Ensure all wireguard interfaces are disabled on startup" + become: true + ansible.builtin.systemd_service: + name: "wg-quick@wg-{{ item }}" + enabled: false + state: "stopped" + when: wireguard_autostart_connection == "" + loop: "{{ wireguard_connections.keys() | list }}" + - name: "Configure autostart connection" become: true when: wireguard_autostart_connection != "" block: - - name: "Ensure all wireguard connections are stopped" - ansible.builtin.systemd_service: - name: "wg-quick@wg-{{ item }}" - enabled: false - state: "stopped" - loop: "{{ wireguard_connections.keys() | list }}" + - name: "Validate wireguard_autostart_connection" + ansible.builtin.assert: + that: + - wireguard_autostart_connection in wireguard_connections.keys() + fail_msg: "wireguard_autostart_connection '{{ wireguard_autostart_connection }}' + is not defined in wireguard_connections" - name: "Ensure all wireguard interfaces are down" ansible.builtin.command: |
