- nameserver: add named-checkconf wrapper that validates the edited fragment in
the context of the full named.conf (lineinfile validate needs %s; isolated
check fails on include-based configs) and surfaces BIND diagnostics on stderr
- base: make wireguard 'when' boolean-correct (ipaddr('public') returns a string)
- base/nameserver: skip step-ca import in base on nameservers (resolv.conf not
yet 127.0.0.1) and import it in the nameserver play after DNS setup
40 lines
1.8 KiB
Bash
Executable File
40 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# Validate a modified BIND config fragment in the context of the full named.conf.
|
|
#
|
|
# Usage: named-checkconf-wrapper.sh <validation-config> <entry-config>
|
|
#
|
|
# Ansible's 'validate' option must contain '%s'. When the module runs, '%s' is
|
|
# replaced with a temporary copy of the file that was just edited (the fragment,
|
|
# e.g. /etc/bind/named.conf.options). named-checkconf, however, only accepts a
|
|
# single config file and the fragment is only valid as part of the main config.
|
|
#
|
|
# This wrapper strips '%s' handling from the caller and instead:
|
|
# 1. takes the modifications that were written to a temporary fragment (%s)
|
|
# 2. creates a temporary copy of the main named.conf where the original
|
|
# fragment path is replaced by that temporary fragment
|
|
# 3. runs named-checkconf against the temporary main config
|
|
#
|
|
# Arguments:
|
|
# $1 fragment_path : the temporary fragment as passed by Ansible ('%s')
|
|
# $2 named_conf : path to the main named.conf
|
|
# $3 fragment_orig : path of the original fragment inside named_conf
|
|
# $4 named_checkconf : path to named-checkconf
|
|
set -eu
|
|
|
|
FRAGMENT="$1"
|
|
NAMED_CONF="${2:-/etc/bind/named.conf}"
|
|
FRAGMENT_ORIG="${3:-/etc/bind/named.conf.options}"
|
|
NAMED_CHECKCONF="${4:-/usr/bin/named-checkconf}"
|
|
|
|
TMP_CONF="$(mktemp "$(dirname "$NAMED_CONF")/.named-checkconf.XXXXXX")"
|
|
trap 'rm -f "$TMP_CONF"' EXIT
|
|
|
|
esc_fragment=$(printf '%s' "$FRAGMENT" | sed 's/[\/&]/\\&/g')
|
|
esc_orig=$(printf '%s' "$FRAGMENT_ORIG" | sed 's/[\/&]/\\&/g')
|
|
sed "s/${esc_orig}/${esc_fragment}/g" "$NAMED_CONF" > "$TMP_CONF"
|
|
|
|
# named-checkconf writes its diagnostics to stdout. Ansible only reports the
|
|
# stderr of a failed 'validate' command, so merge stdout into stderr to make
|
|
# validation failures readable in the playbook output.
|
|
"$NAMED_CHECKCONF" "$TMP_CONF" >&2
|