Refactor(ansible): Correctly generate client config via role
This commit is contained in:
@@ -1,21 +1,20 @@
|
|||||||
- name: wireguard-client-gen
|
- name: Generate WireGuard Client Configuration
|
||||||
hosts: localhost
|
hosts: localhost
|
||||||
#connection: local
|
gather_facts: false
|
||||||
|
|
||||||
vars_files:
|
vars_files:
|
||||||
- ../../group_vars/vault.yml
|
- ../../group_vars/vault.yml
|
||||||
- ../../group_vars/all.yml
|
- ../../group_vars/all.yml
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
user: matej
|
user: matej
|
||||||
IP: "{{ lookup('vars', 'wireguard-client')[user]['ip'] }}"
|
|
||||||
priv: "{{ lookup('vars', 'wireguard-client-vault')[user]['pub'] }}"
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Copy from template
|
- name: Include wireguard_server role to generate client config
|
||||||
template:
|
ansible.builtin.include_role:
|
||||||
src: ../../roles/wireguard_server/templates/wireguardclient.conf
|
name: wireguard_server
|
||||||
dest: ~/{{ user }}.conf
|
tasks_from: generate_client
|
||||||
owner: "{{ ansible_user_id }}"
|
vars:
|
||||||
group: "{{ ansible_user_id }}"
|
# Pass the required variables to the role
|
||||||
mode: '0644'
|
IP: "{{ lookup('vars', 'wireguard-client')[user]['ip'] }}"
|
||||||
|
priv: "{{ lookup('vars', 'wireguard-client-vault')[user]['pub'] }}"
|
||||||
|
|
||||||
|
|||||||
9
roles/wireguard_server/tasks/generate_client.yml
Normal file
9
roles/wireguard_server/tasks/generate_client.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
- name: Generate WireGuard client config
|
||||||
|
template:
|
||||||
|
src: wireguardclient.conf
|
||||||
|
dest: "{{ lookup('env', 'HOME') }}/{{ user }}.conf"
|
||||||
|
owner: "{{ ansible_user_id }}"
|
||||||
|
group: "{{ ansible_user_id }}"
|
||||||
|
mode: '0644'
|
||||||
|
delegate_to: localhost
|
||||||
Reference in New Issue
Block a user