[Interface] PrivateKey = {{ wg_key }} ListenPort = {{ wg_port }} {% if wg_ip4 | default(false) %} Address = {{ wg_ip4 }} {% endif %} {% if wg_ip6 | default(false) %} Address = {{ wg_ip6 }} {% endif %} {% if wg_extraconf | default(false) %} {% for line in wg_extraconf %} {{ line }} {% endfor %} {% endif %} {% for clientname in groups['wg_clients'] %} {% set ip4 = hostvars[clientname].wg_ip4 | default(false) %} {% set ip6 = hostvars[clientname].wg_ip6 | default(false) %} {% set wg_pubkey = pubkeys.results | selectattr('item', 'match', clientname) | map(attribute='stdout') | first %} #{{ clientname }} [Peer] PublicKey = {{ wg_pubkey }} {% if ip4 and ip6 %} AllowedIPs = {{ ip4 }},{{ ip6 }} {% elif ip4 %} AllowedIPs = {{ ip4 }} {% elif ip6 %} AllowedIPs = {{ ip6 }} {% endif %} {% endfor %}