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 --- 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 ++++++++ 5 files changed, 70 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 (limited to 'playbooks.d/dns-dnsmasq') 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 -- cgit v1.1