Refactor(ansible): Correctly generate client config via role

This commit is contained in:
gemini
2026-04-15 19:07:42 +02:00
parent d513ba001a
commit 7c168b5d4e
2 changed files with 21 additions and 13 deletions

View File

@@ -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'] }}"

View 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