Do not regenerate client keys if already configured on server
This commit is contained in:
parent
9aa2fe8bca
commit
894cb17f7e
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
- name: Check if config already exists
|
||||
stat:
|
||||
path: "/etc/wireguard/{{ wg_interface }}.conf"
|
||||
register: interface_configuration
|
||||
|
||||
# - name: Fetching configuration file
|
||||
# ansible.builtin.fetch:
|
||||
# src: "/etc/wireguard/{{ wg_interface }}.conf"
|
||||
# dest: "/tmp/{{ wg_interface }}.conf"
|
||||
|
||||
|
||||
|
||||
- name: Parse configuration
|
||||
ansible.utils.cli_parse:
|
||||
command: "cat /etc/wireguard/{{ wg_interface }}.conf "
|
||||
parser:
|
||||
name: ansible.netcommon.native
|
||||
template_path: templates/wg_config_template.yaml
|
||||
set_fact: existing_wg_config
|
||||
when: interface_configuration.stat.exists
|
||||
|
||||
- name: Check registered peers
|
||||
debug:
|
||||
msg: "Found configs : {{ existing_wg_config }}"
|
||||
|
||||
|
||||
- name: Updating client configs info
|
||||
set_fact:
|
||||
wg_peers: "{{ wg_peers | community.general.lists_mergeby([{'name':item.key,'publicKey':item.value.publicKey}] ,'name')}}"
|
||||
loop: "{{ existing_wg_config | ansible.builtin.dict2items }}"
|
||||
|
||||
- name: Log client configs info
|
||||
debug:
|
||||
msg: "Updated peers defintion : {{ wg_peers }}"
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
- include_tasks: install_wireguard.yaml
|
||||
- include_tasks: gather_current_config.yaml
|
||||
- include_tasks: generate_server_keys.yaml
|
||||
- include_tasks: generate_client_configs.yaml
|
||||
- include_tasks: configure_server.yaml
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
- example: "# Peer ID : fabio_test"
|
||||
getval: '# Peer ID : (?P<peer_id>\S+)'
|
||||
result:
|
||||
"{{ peer_id }}":
|
||||
name: "{{ peer_id }}"
|
||||
shared: true
|
||||
|
||||
- example: "PublicKey = 9a3tgXpF5CAOffbHZdW1QBEJgSLFnBDVbD1JaMPgzkM="
|
||||
getval: 'PublicKey = (?P<publicKey>\S+)'
|
||||
result:
|
||||
"{{ peer_id }}":
|
||||
publicKey: "{{ publicKey }}"
|
||||
Loading…
Reference in New Issue