]> git.phdru.name Git - ansible.git/commitdiff
Feat: Add role to add a DNS domain to named
authorOleg Broytman <phd@phdru.name>
Mon, 29 Jul 2019 22:02:20 +0000 (01:02 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 29 Jul 2019 22:02:20 +0000 (01:02 +0300)
playbooks/debian-add-dns-domain [new file with mode: 0755]
playbooks/debian/roles/add-dns-domain/README.txt [new file with mode: 0644]
playbooks/debian/roles/add-dns-domain/meta/main.yml [new file with mode: 0644]
playbooks/debian/roles/add-dns-domain/tasks/main.yml [new file with mode: 0644]
playbooks/debian/roles/add-dns-domain/templates/domain [new file with mode: 0644]

diff --git a/playbooks/debian-add-dns-domain b/playbooks/debian-add-dns-domain
new file mode 100755 (executable)
index 0000000..b4b865c
--- /dev/null
@@ -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 (file)
index 0000000..8c45ea9
--- /dev/null
@@ -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 (file)
index 0000000..6c17612
--- /dev/null
@@ -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 (file)
index 0000000..8837d99
--- /dev/null
@@ -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 (file)
index 0000000..e2dcd32
--- /dev/null
@@ -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 }}.