From ee8aa3427d674d56e57c034f270388745ed72582 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 30 Jul 2019 01:02:20 +0300 Subject: [PATCH] Feat: Add role to add a DNS domain to named --- playbooks/debian-add-dns-domain | 13 +++++++ .../debian/roles/add-dns-domain/README.txt | 1 + .../debian/roles/add-dns-domain/meta/main.yml | 1 + .../roles/add-dns-domain/tasks/main.yml | 38 +++++++++++++++++++ .../roles/add-dns-domain/templates/domain | 12 ++++++ 5 files changed, 65 insertions(+) create mode 100755 playbooks/debian-add-dns-domain create mode 100644 playbooks/debian/roles/add-dns-domain/README.txt create mode 100644 playbooks/debian/roles/add-dns-domain/meta/main.yml create mode 100644 playbooks/debian/roles/add-dns-domain/tasks/main.yml create mode 100644 playbooks/debian/roles/add-dns-domain/templates/domain 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 }}. -- 2.39.5