diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml index 0f89504..731d0ad 100755 --- a/roles/base/tasks/main.yml +++ b/roles/base/tasks/main.yml @@ -18,7 +18,7 @@ when: - wireguard is defined - wireguard == true - - ansible_default_ipv4.address | ansible.utils.ipaddr('public') + - ansible_default_ipv4.address | ansible.utils.ipaddr('public') | length > 0 ignore_errors: True - import_tasks: system_setup/git.yml # install software @@ -44,6 +44,7 @@ - import_tasks: system_setup/disable_standby.yml when: is_proxmox is defined and is_proxmox == true - import_tasks: system_setup/import_stepca.yml + when: "'nameserver' not in group_names" rescue: diff --git a/roles/nameserver/files/named-checkconf-wrapper.sh b/roles/nameserver/files/named-checkconf-wrapper.sh new file mode 100755 index 0000000..da43059 --- /dev/null +++ b/roles/nameserver/files/named-checkconf-wrapper.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Validate a modified BIND config fragment in the context of the full named.conf. +# +# Usage: named-checkconf-wrapper.sh +# +# 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 diff --git a/roles/nameserver/tasks/configure_bind_snmpd.yml b/roles/nameserver/tasks/configure_bind_snmpd.yml index a1dac1f..33910ab 100755 --- a/roles/nameserver/tasks/configure_bind_snmpd.yml +++ b/roles/nameserver/tasks/configure_bind_snmpd.yml @@ -26,13 +26,21 @@ owner: "bind" group: "bind" +- name: nameserver | snmpd | deploy named-checkconf validation wrapper + copy: + dest: /usr/local/bin/named-checkconf-wrapper.sh + src: "named-checkconf-wrapper.sh" + mode: "0755" + owner: "root" + group: "root" + - name: nameserver | snmpd | configure named for statistics lineinfile: path: "{{ named_conf_options }}" state: present line: '\tstatistics-file "/var/cache/bind/stats";\n\tzone-statistics yes;' insertafter: "options {" - validate: "{{ named_checkconf }} {{ named_conf }}" + validate: "/usr/local/bin/named-checkconf-wrapper.sh %s {{ named_conf }} {{ named_conf_options }} {{ named_checkconf }}" notify: restart_named - name: nameserver | snmpd | configure extend diff --git a/roles/nameserver/tasks/main.yml b/roles/nameserver/tasks/main.yml index 2ed7f6c..a92564b 100755 --- a/roles/nameserver/tasks/main.yml +++ b/roles/nameserver/tasks/main.yml @@ -51,5 +51,13 @@ - name: Nameserver | powerdns-server | configure include_tasks: configure_powerdns_server_snmpd.yml + # Der Base-Play überspringt den step-ca Import auf Nameservern, weil deren + # /etc/resolv.conf erst hier (nach dem DNS-Setup) auf 127.0.0.1 zeigt. + # Jetzt ist die interne Zone auflösbar, also das Root-CA nachziehen. + - name: Nameserver | system setup | import step-ca certificate + include_role: + name: base + tasks_from: system_setup/import_stepca.yml + rescue: - set_fact: task_failed=true