From 9297d5731f8f069c719a9b8812a4fa92cd2a07c0 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 29 Dec 2018 00:54:33 +0100 Subject: wireguard: Creating DNS records file. --- ansible/files/wireguard-dns-records-net1.yml | 25 +++++++++++++++++++++++++ ansible/group_vars/wireguard_net1.yml | 25 +++++++++++++++++++++++++ ansible/group_vars/wireguard_net1/main.yml | 25 ------------------------- ansible/roles/wireguard/tasks/main.yml | 20 ++++++++++++++++++++ 4 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 ansible/files/wireguard-dns-records-net1.yml create mode 100644 ansible/group_vars/wireguard_net1.yml delete mode 100644 ansible/group_vars/wireguard_net1/main.yml diff --git a/ansible/files/wireguard-dns-records-net1.yml b/ansible/files/wireguard-dns-records-net1.yml new file mode 100644 index 0000000..5a3665d --- /dev/null +++ b/ansible/files/wireguard-dns-records-net1.yml @@ -0,0 +1,25 @@ +wireguard_dns_records_net1: + - type: A + name: birgitte + value: 192.168.80.2 + state: present + - type: AAAA + name: birgitte + value: fdf3:aad9:a885:0b3a::2 + state: present + - type: A + name: conflatorio + value: 192.168.80.3 + state: absent + - type: AAAA + name: conflatorio + value: fdf3:aad9:a885:0b3a::3 + state: absent + - type: A + name: fuckaduck + value: 192.168.80.4 + state: present + - type: AAAA + name: fuckaduck + value: fdf3:aad9:a885:0b3a::4 + state: present diff --git a/ansible/group_vars/wireguard_net1.yml b/ansible/group_vars/wireguard_net1.yml new file mode 100644 index 0000000..8e17dea --- /dev/null +++ b/ansible/group_vars/wireguard_net1.yml @@ -0,0 +1,25 @@ +wireguard__net_id: net1 +wireguard__listen_port: 51820 +wireguard__server: + ansible_hostname: knot + hostname: trygvis.io + ipv4: + address: 192.168.80.1 + prefix: 24 + # Generated by https://www.ultratools.com/tools/rangeGenerator + ipv6: + address: fdf3:aad9:a885:0b3a::1 + prefix: 64 +wireguard__clients: + birgitte: + state: present + ipv4: 192.168.80.2 + ipv6: fdf3:aad9:a885:0b3a::2 + conflatorio: + state: absent + ipv4: 192.168.80.3 + ipv6: fdf3:aad9:a885:0b3a::3 + fuckaduck: + state: present + ipv4: 192.168.80.4 + ipv6: fdf3:aad9:a885:0b3a::4 diff --git a/ansible/group_vars/wireguard_net1/main.yml b/ansible/group_vars/wireguard_net1/main.yml deleted file mode 100644 index 8e17dea..0000000 --- a/ansible/group_vars/wireguard_net1/main.yml +++ /dev/null @@ -1,25 +0,0 @@ -wireguard__net_id: net1 -wireguard__listen_port: 51820 -wireguard__server: - ansible_hostname: knot - hostname: trygvis.io - ipv4: - address: 192.168.80.1 - prefix: 24 - # Generated by https://www.ultratools.com/tools/rangeGenerator - ipv6: - address: fdf3:aad9:a885:0b3a::1 - prefix: 64 -wireguard__clients: - birgitte: - state: present - ipv4: 192.168.80.2 - ipv6: fdf3:aad9:a885:0b3a::2 - conflatorio: - state: absent - ipv4: 192.168.80.3 - ipv6: fdf3:aad9:a885:0b3a::3 - fuckaduck: - state: present - ipv4: 192.168.80.4 - ipv6: fdf3:aad9:a885:0b3a::4 diff --git a/ansible/roles/wireguard/tasks/main.yml b/ansible/roles/wireguard/tasks/main.yml index a663be3..9d87c5b 100644 --- a/ansible/roles/wireguard/tasks/main.yml +++ b/ansible/roles/wireguard/tasks/main.yml @@ -133,3 +133,23 @@ rule: allow port: "{{ wireguard__listen_port }}" proto: udp + +- name: generate dns records + tags: wireguard-dns-records + when: wireguard__role == 'server' + local_action: + module: copy + content: | + wireguard_dns_records_{{ wireguard__net_id }}: + {% for c in wireguard__clients|sort %} + {% set client = wireguard__clients[c] %} + - type: A + name: {{ c }} + value: {{ client.ipv4 }} + state: {{ client.state }} + - type: AAAA + name: {{ c }} + value: {{ client.ipv6 }} + state: {{ client.state }} + {% endfor %} + dest: "files/wireguard-dns-records-{{ wireguard__net_id }}.yml" -- cgit v1.2.3