|
| 1 | +--- |
| 2 | +- name: WireGuard | Provision hub on localhost |
| 3 | + hosts: 127.0.0.1 |
| 4 | + become: true |
| 5 | + gather_facts: false |
| 6 | + tags: |
| 7 | + - wireguard |
| 8 | + - wireguard-bring-up |
| 9 | + tasks: |
| 10 | + - name: WireGuard | Capture deployment mode (lxd vs ssh) |
| 11 | + vars: |
| 12 | + ansible_connection: local |
| 13 | + ansible.builtin.set_fact: |
| 14 | + wireguard_deploy_mode: >- |
| 15 | + {{ hostvars[wireguard_hub_inventory_hostname | default('wireguard')]['ansible_connection'] |
| 16 | + | default('lxd') }} |
| 17 | +
|
| 18 | + - name: WireGuard | Set Ansible connection to local |
| 19 | + vars: |
| 20 | + ansible_connection: local |
| 21 | + ansible.builtin.set_fact: |
| 22 | + ansible_connection: local |
| 23 | + |
| 24 | + - name: WireGuard | Gather network facts on host |
| 25 | + ansible.builtin.setup: |
| 26 | + gather_subset: |
| 27 | + - network |
| 28 | + - '!min' |
| 29 | + - name: WireGuard | Validate configuration |
| 30 | + ansible.builtin.include_role: |
| 31 | + name: wireguard |
| 32 | + tasks_from: validate.yml |
| 33 | + when: >- |
| 34 | + (wireguard_enabled | default(false) | bool) |
| 35 | + or (wireguard_data_plane | default(false) | bool) |
| 36 | +
|
| 37 | + - name: WireGuard | Provision hub LXD container (LXD only) |
| 38 | + ansible.builtin.include_role: |
| 39 | + name: wireguard |
| 40 | + tasks_from: lxd_container.yml |
| 41 | + when: |
| 42 | + - wireguard_enabled | default(false) | bool |
| 43 | + - wireguard_deploy_mode == 'lxd' |
| 44 | + |
| 45 | + - name: WireGuard | LXD host port-forward (LXD only) |
| 46 | + ansible.builtin.include_role: |
| 47 | + name: wireguard |
| 48 | + tasks_from: host_portforward.yml |
| 49 | + when: |
| 50 | + - wireguard_enabled | default(false) | bool |
| 51 | + - wireguard_deploy_mode == 'lxd' |
| 52 | + |
| 53 | +- name: WireGuard | Configure hub server |
| 54 | + hosts: "{{ wireguard_hub_inventory_hostname | default('wireguard') }}" |
| 55 | + become: true |
| 56 | + gather_facts: false |
| 57 | + tags: |
| 58 | + - wireguard |
| 59 | + - wireguard-bring-up |
| 60 | + tasks: |
| 61 | + - name: WireGuard | Hub |
| 62 | + ansible.builtin.include_role: |
| 63 | + name: wireguard |
| 64 | + tasks_from: hub.yml |
| 65 | + when: wireguard_enabled | default(false) | bool |
| 66 | + |
| 67 | +- name: WireGuard | Configure peers across app hosts |
| 68 | + hosts: "all:!127.0.0.1:!{{ wireguard_hub_inventory_hostname | default('wireguard') }}" |
| 69 | + become: true |
| 70 | + gather_facts: false |
| 71 | + tags: |
| 72 | + - wireguard |
| 73 | + - wireguard-bring-up |
| 74 | + tasks: |
| 75 | + - name: WireGuard | Restore peer connection (undo backups ansible_connection leak) |
| 76 | + ansible.builtin.set_fact: |
| 77 | + ansible_connection: >- |
| 78 | + {{ hostvars[wireguard_hub_inventory_hostname | default('wireguard')]['ansible_connection'] |
| 79 | + | default('lxd') }} |
| 80 | + when: wireguard_enabled | default(false) | bool |
| 81 | + |
| 82 | + - name: WireGuard | Peer |
| 83 | + ansible.builtin.include_role: |
| 84 | + name: wireguard |
| 85 | + tasks_from: peer.yml |
| 86 | + when: |
| 87 | + - wireguard_enabled | default(false) | bool |
| 88 | + - hostvars[inventory_hostname].wireguard_ip is defined |
| 89 | + - hostvars[inventory_hostname].wireguard_ip | length > 0 |
0 commit comments