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]"