summaryrefslogtreecommitdiff
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
parentfbb7e8511be3b590f0cd8a915ef8ef62cae67f65 (diff)
Add playbook for dnsmasq
-rw-r--r--defaults6
-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
-rw-r--r--registry.d/anoia.tyil.net1
7 files changed, 77 insertions, 0 deletions
diff --git a/defaults b/defaults
index 04eb9ee..1d4a1e1 100644
--- a/defaults
+++ b/defaults
@@ -5,3 +5,9 @@ k3s.network.cidr.pods=10.57.40.0/20
k3s.network.cidr.svcs=10.57.48.0/20
k3s.network.service.dns=10.57.48.53
k3s.flux.repo.url=ssh://git@10.57.100.7/srv/git/tyilnet
+dns.domain=tyil.net
+dns.upstream.0=185.181.61.24
+dns.upstream.1=188.68.231.82
+dns.upstream.2=51.83.172.84
+dns.upstream.3=2a03:94e0:1804::1
+dns.upstream.4=2001:470:71:6dc::53
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
diff --git a/registry.d/anoia.tyil.net b/registry.d/anoia.tyil.net
index 8cb0a70..059d70d 100644
--- a/registry.d/anoia.tyil.net
+++ b/registry.d/anoia.tyil.net
@@ -1,4 +1,5 @@
backup-borg
+dns-dnsmasq
ssh
user-tyil
vpn-tinc