|
|
@ -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
|
|
|
|
|
|
|
|
|
|
|
|