dnsmasq: add script for dynamic DNS updates

This commit is contained in:
Timotej Lazar 2024-08-02 12:08:32 +02:00
parent a3dd4eba65
commit 01a27e45ce
4 changed files with 75 additions and 1 deletions

View file

@ -2,6 +2,32 @@
package: package:
name: name:
- dnsmasq - dnsmasq
- bind-tools
- krb5
- py3-pexpect
- name: Configure kerberos
template:
dest: /etc/krb5.conf
src: krb5.conf.j2
- name: Init kerberos keytab
expect:
command: ktutil
responses:
'.*:':
- 'add_entry -password -p {{ password.ldap_user }} -k 1 -e aes256-cts-hmac-sha1-96'
- '{{ password.ldap_pass }}'
- 'write_kt /etc/krb5.keytab'
- 'exit'
args:
creates: /etc/krb5.keytab
- name: Copy DNS updater script
template:
dest: "/usr/local/bin/dns-update"
src: "dns-update.j2"
mode: 0700
- name: Configure dnsmasq - name: Configure dnsmasq
template: template:
@ -12,5 +38,4 @@
- 10-ranges.conf - 10-ranges.conf
notify: restart dnsmasq notify: restart dnsmasq
# TODO DNS update
# TODO netboot config # TODO netboot config

View file

@ -9,3 +9,5 @@ dhcp-proxy
dhcp-option = option:dns-server,{{ dns | join(',') }} dhcp-option = option:dns-server,{{ dns | join(',') }}
dhcp-option = option:ntp-server,{{ ntp | join(',') }} dhcp-option = option:ntp-server,{{ ntp | join(',') }}
dhcp-script = /usr/local/bin/dns-update

View file

@ -0,0 +1,29 @@
#!/bin/sh
domain={{ domain }}
ldap_user={{ password.ldap_user }}
ttl=3600
address="${3}"
case "${1}" in
add)
host="${4}"
kinit -k "${ldap_user}"
nsupdate -g <<EOF
update add ${host}.${domain} ${ttl} A ${address}
send
EOF
;;
old)
if [ -n "${DNSMASQ_OLD_HOSTNAME}" -a -n "${DNSMASQ_SUPPLIED_HOSTNAME}" ] ; then
kinit -k "${ldap_user}"
nsupdate -g <<EOF
update del ${DNSMASQ_OLD_HOSTNAME}.${domain}
update add ${DNSMASQ_SUPPLIED_HOSTNAME}.${domain} ${ttl} A ${address}
send
EOF
fi
;;
# TODO del, probably
esac

View file

@ -0,0 +1,18 @@
[libdefaults]
dns_lookup_realm = false
ticket_lifetime = 24h
renew_lifetime = 7d
#forwardable = true
rdns = false
default_realm = {{ domain | upper }}
[realms]
{{ domain | upper }} = {
{% for server in dns %}
kdc = {{ server }}
{% endfor %}
}
[domain_realm]
.{{ domain }} = {{ domain | upper }}
{{ domain }} = {{ domain | upper }}