From 0647b54b62ed7969f55c07a05b2d05ac53ea5b66 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Mon, 17 Oct 2022 12:34:56 +0200 Subject: Add playbook for dnsmasq --- defaults | 6 ++++ playbooks.d/dns-dnsmasq/description.txt | 1 + playbooks.d/dns-dnsmasq/etc/defaults | 6 ++++ playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo | 1 + playbooks.d/dns-dnsmasq/playbook.bash | 48 +++++++++++++++++++++++++++ playbooks.d/dns-dnsmasq/share/dnsmasq.conf | 14 ++++++++ registry.d/anoia.tyil.net | 1 + 7 files changed, 77 insertions(+) create mode 100644 playbooks.d/dns-dnsmasq/description.txt create mode 100644 playbooks.d/dns-dnsmasq/etc/defaults create mode 100644 playbooks.d/dns-dnsmasq/etc/os.d/linux-gentoo create mode 100644 playbooks.d/dns-dnsmasq/playbook.bash create mode 100644 playbooks.d/dns-dnsmasq/share/dnsmasq.conf 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 -- cgit v1.1