---
- name: "π Check whether '{{ mesh_name }}' is already up"
ansible.builtin.command: "wg show {{ mesh_name | quote }}"
register: wireguard_present
changed_when: false
failed_when: false
- name: "πΊ Bring '{{ mesh_name }}' up"
ansible.builtin.command: "wg-quick up {{ mesh_name | quote }}"
register: wireguard_up
changed_when: wireguard_up.rc == 0
when: wireguard_present.rc != 0
- name: "β»οΈ Converge the live '{{ mesh_name }}' in place"
when: wireguard_present.rc == 0
block:
- name: "β»οΈ Reconfigure the live '{{ mesh_name }}' in place"
ansible.builtin.shell: >
set -o pipefail && wg syncconf {{ mesh_name | quote }}
<(wg-quick strip {{ mesh_name | quote }})
args:
executable: /bin/bash
register: wireguard_synced
changed_when: wireguard_synced.rc == 0
- name: "π Read the link MTU of the live '{{ mesh_name }}'"
ansible.builtin.command:
argv:
- ip
- -j
- link
- show
- dev
- "{{ mesh_name }}"
register: wireguard_link
changed_when: false
- name: "π Apply the tunnel MTU to the live '{{ mesh_name }}'"
ansible.builtin.command:
argv:
- ip
- link
- set
- dev
- "{{ mesh_name }}"
- mtu
- "{{ wireguard_mtu | int }}"
changed_when: true
when: (wireguard_link.stdout | from_json | first).mtu | int != wireguard_mtu | int