-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not regenerate keys if they already in place
- Loading branch information
1 parent
6e9b529
commit 98415db
Showing
1 changed file
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
--- | ||
- name: Generate WireGuard private key | ||
command: "wg genkey" | ||
register: wireguard_register_private_key | ||
changed_when: false | ||
- name: Register if config/private key already exists on target host | ||
stat: | ||
path: "/etc/wireguard/{{ wireguard_interface }}.conf" | ||
register: wireguard_register_config_file | ||
|
||
- block: | ||
- name: Read WireGuard config file | ||
slurp: | ||
src: "/etc/wireguard/{{ wireguard_interface }}.conf" | ||
register: wireguard_register_config | ||
|
||
- name: Set private key | ||
set_fact: | ||
wireguard_private_key: "{{ wireguard_register_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}" | ||
when: | ||
- wireguard_register_config_file.stat.exists | ||
|
||
- block: | ||
- name: Generate WireGuard private key | ||
command: "wg genkey" | ||
register: wireguard_register_private_key | ||
changed_when: false | ||
|
||
- name: Set private key | ||
set_fact: | ||
wireguard_private_key: "{{ wireguard_register_private_key.stdout }}" | ||
when: | ||
- not wireguard_register_config_file.stat.exists | ||
- wireguard_private_key is not defined | ||
|
||
- name: Set private key fact | ||
set_fact: | ||
wireguard_private_key: "{{ wireguard_register_private_key.stdout }}" | ||
|
||
- name: Derive WireGuard public key | ||
- name: Generate WireGuard public key | ||
command: "wg pubkey" | ||
args: | ||
stdin: "{{ wireguard_private_key }}" | ||
register: wireguard_register_public_key | ||
changed_when: false | ||
|
||
- name: Set public key fact | ||
- name: Set public key | ||
set_fact: | ||
wireguard_fact_public_key: "{{ wireguard_register_public_key.stdout }}" |