From 0e0dda8acf88f53f086645720b18328ae407d78d Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 6 Oct 2023 22:48:29 +0300 Subject: [PATCH] get IP address --- tasks/configure.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index 7f9f3d3..f8a3e3b 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -61,7 +61,8 @@ # - Restart Wireguard service # - Ping Wireguard server -- name: Configure peers hosts file entry + +- name: Configure peers hosts file entry (from wg_address) lineinfile: path: /etc/hosts regexp: "^{{ hostvars[item]['wg_address'] | regex_replace('/.*$', '')}} " @@ -69,3 +70,14 @@ backup: true create: true loop: "{{ groups['wireguard_clients'] }}" + when: "'wg_address' in hostvars[item]" + +- name: Configure peers hosts file entry (from allowed IPs) + lineinfile: + path: /etc/hosts + regexp: "^{{ hostvars[item]['AllowedIPs'] | regex_replace('/.*$', '')}} " + line: "{{ hostvars[item]['AllowedIPs'] | regex_replace('/.*$', '')}} {{ item }}.{{ vpn_domain }}" + backup: true + create: true + loop: "{{ groups['wireguard_clients'] }}" + when: "'wg_address' not in hostvars[item]"