Role network-loopback: set internal nameserver when available
This commit is contained in:
parent
52d55e3997
commit
7b2f330c3a
2 changed files with 36 additions and 0 deletions
|
@ -4,3 +4,17 @@
|
||||||
src: loopback.j2
|
src: loopback.j2
|
||||||
dest: "/etc/network/interfaces.d/loopback"
|
dest: "/etc/network/interfaces.d/loopback"
|
||||||
notify: reload network interfaces
|
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"
|
||||||
|
|
22
roles/network-loopback/templates/check-anycast.sh.j2
Normal file
22
roles/network-loopback/templates/check-anycast.sh.j2
Normal 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
|
Loading…
Reference in a new issue