From: Oleg Broytman Date: Mon, 29 Jul 2019 22:02:20 +0000 (+0300) Subject: Feat: Add role to add a DNS domain to named X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=ee8aa3427d674d56e57c034f270388745ed72582;p=ansible.git Feat: Add role to add a DNS domain to named --- diff --git a/playbooks/debian-add-dns-domain b/playbooks/debian-add-dns-domain new file mode 100755 index 0000000..b4b865c --- /dev/null +++ b/playbooks/debian-add-dns-domain @@ -0,0 +1,13 @@ +#! /bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 domain" >&2 + exit 1 +fi + +domain="$1" +shift + +cd "`dirname \"$0\"`" && +ANSIBLE_ROLES_PATH=debian/roles \ + exec ./run-role add-dns-domain "$@" -e domain="$domain" diff --git a/playbooks/debian/roles/add-dns-domain/README.txt b/playbooks/debian/roles/add-dns-domain/README.txt new file mode 100644 index 0000000..8c45ea9 --- /dev/null +++ b/playbooks/debian/roles/add-dns-domain/README.txt @@ -0,0 +1 @@ +Add a DNS domain to named (BIND). diff --git a/playbooks/debian/roles/add-dns-domain/meta/main.yml b/playbooks/debian/roles/add-dns-domain/meta/main.yml new file mode 100644 index 0000000..6c17612 --- /dev/null +++ b/playbooks/debian/roles/add-dns-domain/meta/main.yml @@ -0,0 +1 @@ +dependencies: ['named'] diff --git a/playbooks/debian/roles/add-dns-domain/tasks/main.yml b/playbooks/debian/roles/add-dns-domain/tasks/main.yml new file mode 100644 index 0000000..8837d99 --- /dev/null +++ b/playbooks/debian/roles/add-dns-domain/tasks/main.yml @@ -0,0 +1,38 @@ +- name: Check domain + stat: + path: "/etc/bind/{{ domain }}" + register: domain_exists + +- name: Copy domain template + become: true + template: + src: domain + dest: "/etc/bind/{{ domain }}" + owner: bind + group: bind + mode: '0600' + force: no + when: not domain_exists.stat.exists + +- name: Update config + become: true + shell: | +echo ' + +zone "{{ domain }}" { + type master; + file "/etc/bind/{{ domain }}"; + allow-query { any; }; + notify yes; +}; +' >> /etc/bind/named.conf.local + + + when: not domain_exists.stat.exists + +- name: Reload BIND + become: true + service: + name: bind9 + state: reloaded + when: not domain_exists.stat.exists diff --git a/playbooks/debian/roles/add-dns-domain/templates/domain b/playbooks/debian/roles/add-dns-domain/templates/domain new file mode 100644 index 0000000..e2dcd32 --- /dev/null +++ b/playbooks/debian/roles/add-dns-domain/templates/domain @@ -0,0 +1,12 @@ +$TTL 86400 +@ IN SOA ns1.{{ domain }}. hostmaster.{{ domain }}. ( + {{ now().strftime('%Y%m%d') }}00 ; Serial + 86400 ; Refresh 1d + 3600 ; Retry 1h + 2419200 ; Expire 28 days + 86400) ; Default TTL 1d + + IN NS ns1.{{ domain }}. + IN A ??? +ns1 IN A ??? +www IN CNAME {{ domain }}.