summaryrefslogtreecommitdiff
path: root/playbooks.d/dns-dnsmasq
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2022-10-17 12:34:56 +0200
committerPatrick Spek <p.spek@tyil.nl>2022-10-17 12:34:56 +0200
commit0647b54b62ed7969f55c07a05b2d05ac53ea5b66 (patch)
tree3282506ea6f2103d7f93fe2fe9a810642f167ca5 /playbooks.d/dns-dnsmasq
parentfbb7e8511be3b590f0cd8a915ef8ef62cae67f65 (diff)
Add playbook for dnsmasq
Diffstat (limited to 'playbooks.d/dns-dnsmasq')
-rw-r--r--playbooks.d/dns-dnsmasq/description.txt1
-rw-r--r--playbooks.d/dns-dnsmasq/etc/defaults6
-rw-r--r--playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo1
-rw-r--r--playbooks.d/dns-dnsmasq/playbook.bash48
-rw-r--r--playbooks.d/dns-dnsmasq/share/dnsmasq.conf14
5 files changed, 70 insertions, 0 deletions
diff --git a/playbooks.d/dns-dnsmasq/description.txt b/playbooks.d/dns-dnsmasq/description.txt
new file mode 100644
index 0000000..0c12e3a
--- /dev/null
+++ b/playbooks.d/dns-dnsmasq/description.txt
@@ -0,0 +1 @@
+Local DNS resolver with dnsmasq
diff --git a/playbooks.d/dns-dnsmasq/etc/defaults b/playbooks.d/dns-dnsmasq/etc/defaults
new file mode 100644
index 0000000..4d3305a
--- /dev/null
+++ b/playbooks.d/dns-dnsmasq/etc/defaults
@@ -0,0 +1,6 @@
+pkg.dnsmasq=dnsmasq
+svc.dnsmasq=dnsmasq
+
+dns.port=53
+dns.host=127.0.0.1
+dns.domain=localhost
diff --git a/playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo b/playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo
new file mode 100644
index 0000000..2aec434
--- /dev/null
+++ b/playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo
@@ -0,0 +1 @@
+pkg.dnsmasq=net-dns/dnsmasq
diff --git a/playbooks.d/dns-dnsmasq/playbook.bash b/playbooks.d/dns-dnsmasq/playbook.bash
new file mode 100644
index 0000000..f4be8cd
--- /dev/null
+++ b/playbooks.d/dns-dnsmasq/playbook.bash
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+playbook_add() {
+ info "$BASHTARD_PLAYBOOK" "Installing packages"
+ pkg install dnsmasq
+
+ playbook_sync
+
+ info "$BASHTARD_PLAYBOOK" "Enabling services"
+ svc enable dnsmasq
+ svc start dnsmasq
+}
+
+playbook_sync() {
+ mkdir -pv -- "$(config "fs.etcdir")/dnsmasq.d"
+
+ info "$BASHTARD_PLAYBOOK" "Writing config"
+ file_template "dnsmasq.conf" \
+ "host=$(config "dns.host")" \
+ "port=$(config "dns.port")" \
+ "domain=$(config "dns.domain")" \
+ "confd=$(config "fs.etcdir")/dnsmasq.d" \
+ > "$(config "fs.etcdir")/dnsmasq.conf"
+
+ while read -r key
+ do
+ printf "server=%s\n" "$(config "dns.upstream.$key")"
+ done < <(config_subkeys "dns.upstream") > "$(config "fs.etcdir")/dnsmasq.d/servers.conf"
+
+ while read -r key
+ do
+ printf "address=/$(config "dns.address.$key" | sed s@:@/@)\n"
+ done < <(config_subkeys "dns.address") > "$(config "fs.etcdir")/dnsmasq.d/addresses.conf"
+
+ [[ "$BASHTARD_COMMAND" == "add" ]] && return
+
+ info "$BASHTARD_PLAYBOOK" "Restarting services"
+ svc restart dnsmasq
+}
+
+playbook_del() {
+ info "$BASHTARD_PLAYBOOK" "Disabling services"
+ svc stop dnsmasq
+ svc disable dnsmasq
+
+ info "$BASHTARD_PLAYBOOK" "Uninstalling packages"
+ pkg uninstall dnsmasq
+}
diff --git a/playbooks.d/dns-dnsmasq/share/dnsmasq.conf b/playbooks.d/dns-dnsmasq/share/dnsmasq.conf
new file mode 100644
index 0000000..4fe090c
--- /dev/null
+++ b/playbooks.d/dns-dnsmasq/share/dnsmasq.conf
@@ -0,0 +1,14 @@
+# Binding
+listen-address=${host}
+port=${port}
+bind-interfaces
+
+# Local domain
+domain=${domain}
+
+# Upstream DNS Servers
+no-resolv
+conf-file=${confd}/servers.conf
+
+# Addresses
+conf-file=${confd}/addresses.conf