From 5db3e19630e90f70cb5875f01c267ce74c1f0649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bourqui?= Date: Fri, 18 Oct 2019 23:14:30 +0200 Subject: [PATCH] fix private key creation --- tasks/main.yml | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index a311ef9..7d4cdb1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -38,25 +38,34 @@ tags: - wg-generate-keys -- name: Generate WireGuard private key - shell: "wg genkey" - register: wg_private_key_result +- block: + - name: Generate WireGuard private key + shell: "wg genkey" + register: wg_private_key_result + tags: + - wg-generate-keys + + - name: Set private key fact + set_fact: + private_key: "{{ wg_private_key_result.stdout }}" + tags: + - wg-generate-keys when: not config_file_stat.stat.exists - tags: - - wg-generate-keys -- name: Read WireGuard config file - slurp: - src: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf" - register: wg_config - tags: - - wg-config +- block: + - name: Read WireGuard config file + slurp: + src: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf" + register: wg_config + tags: + - wg-config -- name: Set private key fact - set_fact: - private_key: "{{ wg_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}" - tags: - - wg-config + - name: Set private key fact + set_fact: + private_key: "{{ wg_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}" + tags: + - wg-config + when: config_file_stat.stat.exists - name: Derive WireGuard public key shell: "echo '{{ private_key }}' | wg pubkey"