Use common namespace "wireguard" for role facts
This commit is contained in:
parent
7a1af464b1
commit
c4a21dd0ef
4 changed files with 26 additions and 26 deletions
|
@ -31,19 +31,19 @@
|
||||||
- name: Register if config/private key already exists on target host
|
- name: Register if config/private key already exists on target host
|
||||||
stat:
|
stat:
|
||||||
path: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
path: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
||||||
register: config_file_stat
|
register: wireguard__register_config_file
|
||||||
tags:
|
tags:
|
||||||
- wg-generate-keys
|
- wg-generate-keys
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
- name: Get wg subcommands
|
- name: Get wg subcommands
|
||||||
command: "wg --help"
|
command: "wg --help"
|
||||||
register: wg_subcommands
|
register: wireguard__register_subcommands
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Check if wg syncconf subcommand is available
|
- name: Check if wg syncconf subcommand is available
|
||||||
set_fact:
|
set_fact:
|
||||||
wg_syncconf: "{{ 'syncconf:' in wg_subcommands.stdout }}"
|
wg_syncconf: "{{ 'syncconf:' in wireguard__register_subcommands.stdout }}"
|
||||||
|
|
||||||
- name: Show syncconf subcommand status
|
- name: Show syncconf subcommand status
|
||||||
debug:
|
debug:
|
||||||
|
@ -52,43 +52,43 @@
|
||||||
- block:
|
- block:
|
||||||
- name: Generate WireGuard private key
|
- name: Generate WireGuard private key
|
||||||
command: "wg genkey"
|
command: "wg genkey"
|
||||||
register: wg_private_key_result
|
register: wireguard__register_private_key
|
||||||
changed_when: false
|
changed_when: false
|
||||||
tags:
|
tags:
|
||||||
- wg-generate-keys
|
- wg-generate-keys
|
||||||
|
|
||||||
- name: Set private key fact
|
- name: Set private key fact
|
||||||
set_fact:
|
set_fact:
|
||||||
private_key: "{{ wg_private_key_result.stdout }}"
|
wireguard__fact_private_key: "{{ wireguard__register_private_key.stdout }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-generate-keys
|
- wg-generate-keys
|
||||||
when: not config_file_stat.stat.exists
|
when: not wireguard__register_config_file.stat.exists
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Read WireGuard config file
|
- name: Read WireGuard config file
|
||||||
slurp:
|
slurp:
|
||||||
src: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
src: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
||||||
register: wg_config
|
register: wireguard__register_config
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
- name: Set private key fact
|
- name: Set private key fact
|
||||||
set_fact:
|
set_fact:
|
||||||
private_key: "{{ wg_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}"
|
wireguard__fact_private_key: "{{ wireguard__register_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
when: config_file_stat.stat.exists
|
when: wireguard__register_config_file.stat.exists
|
||||||
|
|
||||||
- name: Derive WireGuard public key
|
- name: Derive WireGuard public key
|
||||||
shell: "echo '{{ private_key }}' | wg pubkey" # noqa 306
|
shell: "echo '{{ wireguard__fact_private_key }}' | wg pubkey" # noqa 306
|
||||||
register: wg_public_key_result
|
register: wireguard__register_public_key
|
||||||
changed_when: false
|
changed_when: false
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
- name: Set public key fact
|
- name: Set public key fact
|
||||||
set_fact:
|
set_fact:
|
||||||
public_key: "{{ wg_public_key_result.stdout }}"
|
wireguard__fact_public_key: "{{ wireguard__register_public_key.stdout }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
name:
|
name:
|
||||||
- "raspberrypi-kernel"
|
- "raspberrypi-kernel"
|
||||||
state: latest
|
state: latest
|
||||||
register: kernel_update
|
register: wireguard__register_kernel_update
|
||||||
tags:
|
tags:
|
||||||
- wg-install
|
- wg-install
|
||||||
|
|
||||||
|
@ -36,21 +36,21 @@
|
||||||
search_paths: ['/lib/molly-guard', '/usr/sbin']
|
search_paths: ['/lib/molly-guard', '/usr/sbin']
|
||||||
when:
|
when:
|
||||||
- ansible_version.full is version('2.8.0', '>=')
|
- ansible_version.full is version('2.8.0', '>=')
|
||||||
- kernel_update is changed
|
- wireguard__register_kernel_update is changed
|
||||||
tags:
|
tags:
|
||||||
- wg-install
|
- wg-install
|
||||||
|
|
||||||
- name: (Raspbian) Check if molly-guard is installed (Ansible < 2.8)
|
- name: (Raspbian) Check if molly-guard is installed (Ansible < 2.8)
|
||||||
stat:
|
stat:
|
||||||
path: /lib/molly-guard/
|
path: /lib/molly-guard/
|
||||||
register: molly_guard
|
register: wireguard__register_molly_guard
|
||||||
|
|
||||||
- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, no molly-guard)
|
- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, no molly-guard)
|
||||||
reboot:
|
reboot:
|
||||||
when:
|
when:
|
||||||
- ansible_version.full is version('2.8.0', '<')
|
- ansible_version.full is version('2.8.0', '<')
|
||||||
- kernel_update is changed
|
- wireguard__register_kernel_update is changed
|
||||||
- not molly_guard.stat.exists
|
- not wireguard__register_molly_guard.stat.exists
|
||||||
tags:
|
tags:
|
||||||
- wg-install
|
- wg-install
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@
|
||||||
ignore_unreachable: yes
|
ignore_unreachable: yes
|
||||||
when:
|
when:
|
||||||
- ansible_version.full is version('2.8.0', '<')
|
- ansible_version.full is version('2.8.0', '<')
|
||||||
- kernel_update is changed
|
- wireguard__register_kernel_update is changed
|
||||||
- molly_guard.stat.exists
|
- wireguard__register_molly_guard.stat.exists
|
||||||
tags:
|
tags:
|
||||||
- wg-install
|
- wg-install
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@
|
||||||
wait_for_connection:
|
wait_for_connection:
|
||||||
when:
|
when:
|
||||||
- ansible_version.full is version('2.8.0', '<')
|
- ansible_version.full is version('2.8.0', '<')
|
||||||
- kernel_update is changed
|
- wireguard__register_kernel_update is changed
|
||||||
- molly_guard.stat.exists
|
- wireguard__register_molly_guard.stat.exists
|
||||||
tags:
|
tags:
|
||||||
- wg-install
|
- wg-install
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
- include_tasks: "setup-debian-raspbian.yml"
|
- include_tasks: "setup-debian-raspbian.yml"
|
||||||
when: ansible_lsb.id == "Raspbian"
|
when: ansible_lsb.id == "Raspbian"
|
||||||
register: raspbian_setup
|
register: wireguard__register_raspbian_setup
|
||||||
|
|
||||||
- include_tasks: "setup-debian-vanilla.yml"
|
- include_tasks: "setup-debian-vanilla.yml"
|
||||||
when: raspbian_setup is skipped
|
when: wireguard__register_raspbian_setup is skipped
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
[Interface]
|
[Interface]
|
||||||
# {{ inventory_hostname }}
|
# {{ inventory_hostname }}
|
||||||
Address = {{hostvars[inventory_hostname].wireguard_address}}
|
Address = {{hostvars[inventory_hostname].wireguard_address}}
|
||||||
PrivateKey = {{private_key}}
|
PrivateKey = {{ wireguard__fact_private_key }}
|
||||||
ListenPort = {{wireguard_port}}
|
ListenPort = {{ wireguard_port }}
|
||||||
{% if hostvars[inventory_hostname].wireguard_dns is defined %}
|
{% if hostvars[inventory_hostname].wireguard_dns is defined %}
|
||||||
DNS = {{hostvars[inventory_hostname].wireguard_dns}}
|
DNS = {{hostvars[inventory_hostname].wireguard_dns}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -44,7 +44,7 @@ SaveConfig = true
|
||||||
|
|
||||||
[Peer]
|
[Peer]
|
||||||
# {{ host }}
|
# {{ host }}
|
||||||
PublicKey = {{hostvars[host].public_key}}
|
PublicKey = {{hostvars[host].wireguard__fact_public_key}}
|
||||||
{% if hostvars[host].wireguard_allowed_ips is defined %}
|
{% if hostvars[host].wireguard_allowed_ips is defined %}
|
||||||
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
|
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue