Role network-loopback: set internal nameserver when available

This commit is contained in:
Julian Labus 2019-03-23 15:05:36 +01:00
parent 52d55e3997
commit 7b2f330c3a
No known key found for this signature in database
GPG key ID: 8AF209F2C6B3572A
2 changed files with 36 additions and 0 deletions

View file

@ -4,3 +4,17 @@
src: loopback.j2
dest: "/etc/network/interfaces.d/loopback"
notify: reload network interfaces
- name: create check-anycast.sh
template:
src: check-anycast.sh.j2
dest: "/usr/local/bin/check-anycast.sh"
owner: root
group: root
mode: 0755
- name: create cronjob for check-anycast.sh"
cron:
name: "check anycast availability"
minute: "*/1"
job: "/usr/local/bin/check-anycast.sh > /dev/null 2>&1"

View file

@ -0,0 +1,22 @@
#!/bin/bash
LOOPBACK="loopback"
ANYCAST="{{ anycast_ipv4 | ipaddr('address') }}"
ANYCAST_PRESENT=false
if ping -c 1 "${ANYCAST}" > /dev/null 2>&1 ; then
ANYCAST_PRESENT=true
fi
DNS_PRESENT=false
if /sbin/resolvconf -l "${LOOPBACK}" > /dev/null 2>&1 ; then
DNS_PRESENT=true
fi
if [[ ${ANYCAST_PRESENT} == true && ${DNS_PRESENT} == true ]] ; then
exit 0
elif [[ ${ANYCAST_PRESENT} == true && ${DNS_PRESENT} == false ]] ; then
echo "nameserver ${ANYCAST}" | /sbin/resolvconf -a "${LOOPBACK}" -m 1
elif [[ ${ANYCAST_PRESENT} == false && ${DNS_PRESENT} == true ]] ; then
/sbin/resolvconf -d "${LOOPBACK}"
fi