--- # Restart the WireGuard tunnel interface. # Run: ansible-playbook -i inventory/hosts.yml playbooks/bf-wireguard-restart.yml -e operation_wave=lab -e operation_confirmed=true --limit lab # Uses wg_interface from group_vars and defaults to wg0. # No Semaphore Pro feature is used. - name: Restart WireGuard tunnel hosts: "{{ operation_wave | default('invalid-wave', true) }}" gather_facts: false become: true vars: approved_operation_waves: [lab, pilot_1, pilot_2, wave_1, wave_2, production] production_override: false wireguard_restart_interface: "{{ wg_interface | default('wg0') }}" pre_tasks: - name: Require confirmed approved operation wave scope ansible.builtin.assert: that: - operation_wave in approved_operation_waves - operation_confirmed | bool - operation_wave in groups - ansible_play_hosts_all | length > 0 - ansible_play_hosts_all | difference(groups[operation_wave]) | length == 0 fail_msg: "Set operation_wave to one inventory wave and operation_confirmed=true; full-fleet scope is refused." run_once: true - name: Require separate production override ansible.builtin.assert: that: - operation_wave != 'production' or production_override | bool fail_msg: "Production operation requires production_override=true in addition to operation_confirmed=true." run_once: true tasks: - name: Restart WireGuard service ansible.builtin.systemd: name: "wg-quick@{{ wireguard_restart_interface }}" state: restarted - name: Verify tunnel state ansible.builtin.command: argv: [wg, show, "{{ wireguard_restart_interface }}"] register: wg_out changed_when: false - name: Show WireGuard state ansible.builtin.debug: msg: "{{ inventory_hostname }}: {{ wg_out.stdout_lines | default([]) }}"