Ian Wienand 401520e274 Add unbound role
As mentioned in the README, this adds the dynamic configuration for
unbound on hosts. If there is a ipv6 route, it will set forwarding to
ipv6 servers, otherwise use ipv4. This is ported from the
configure_mirror.sh script.

We add a basic test to integration tests

Change-Id: I70b41e45f3d53b191742533c2f3b6c0b6e6c2339
2017-10-11 10:20:16 +11:00

44 lines
1.2 KiB
YAML

- name: Ensure /etc/unbound exists
become: yes
file:
path: /etc/unbound
state: directory
owner: root
group: root
mode: 0755
# Use *only* ipv6 resolvers if ipv6 is present and routable
# (ansible_default_ipv6 should only be defined for a global, routable
# address). This avoids traversing potential NAT when using ipv4 which
# can be unreliable.
- name: Set IPv6 nameservers
when: ansible_default_ipv6.address is defined
set_fact:
primary_nameserver: '{{ primary_nameserver_v6 }}'
secondary_nameserver: '{{ secondary_nameserver_v6 }}'
# Fallback to default ipv4 if there is no ipv6 available as this
# causes timeouts and failovers that are unnecesary.
- name: Set IPv4 nameservers
when:
- ansible_default_ipv6.address is not defined
set_fact:
primary_nameserver: '{{ primary_nameserver_v4 }}'
secondary_nameserver: '{{ secondary_nameserver_v4 }}'
- name: Configure unbound fowarding
become: yes
template:
dest: '/etc/unbound/forwarding.conf'
owner: root
group: root
mode: 0644
src: forwarding.conf.j2
- name: restart unbound
become: yes
service:
name: unbound
state: restarted
enabled: yes