get IP address

This commit is contained in:
Antonio J. Delgado 2023-10-06 22:48:29 +03:00
parent 5a8c281342
commit 0e0dda8acf

View file

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