openstack-zuul-jobs/roles/configure-unbound/tasks/main.yaml

85 lines
2.3 KiB
YAML

# This role assumes that Unbound is already installed, fail early if it isn't.
- name: Check that Unbound is installed
stat:
path: /etc/unbound
register: unbound_config
- name: Ensure that Unbound is installed
assert:
that:
- unbound_config.stat.exists
# ansible_default_ipv6 can either be undefined (no ipv6) or blank (no
# routable address). We only want to use ipv6 if it's available &
# routable; combine these checks into this fact.
- name: Check for IPv6
when:
- ansible_default_ipv6 is defined
- ansible_default_ipv6.address is defined
set_fact:
unbound_use_ipv6: True
# Use *only* ipv6 resolvers if ipv6 is present and routable. This
# avoids traversing potential NAT when using ipv4 which can be
# unreliable.
- name: Set IPv6 nameservers
when:
- unbound_use_ipv6 is defined
set_fact:
unbound_primary_nameserver: '{{ unbound_primary_nameserver_v6 }}'
unbound_secondary_nameserver: '{{ unbound_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:
- unbound_use_ipv6 is not defined
set_fact:
unbound_primary_nameserver: '{{ unbound_primary_nameserver_v4 }}'
unbound_secondary_nameserver: '{{ unbound_secondary_nameserver_v4 }}'
- name: Include OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ role_path }}/vars/{{ ansible_distribution }}.yaml"
- "{{ role_path }}/vars/{{ ansible_os_family }}.yaml"
- "{{ role_path }}/vars/default.yaml"
- name: Ensure Unbound conf.d directory exists
become: yes
file:
path: "{{ unbound_confd }}"
state: directory
# TODO: Move this to /etc/unbound/conf.d ?
- name: Configure unbound forwarding
become: yes
template:
dest: /etc/unbound/forwarding.conf
owner: root
group: root
mode: 0644
src: forwarding.conf.j2
register: forwarding_config
notify:
- Restart unbound
- name: Configure unbound TTL
become: yes
template:
dest: "{{ unbound_confd }}/ttl.conf"
owner: root
group: root
mode: 0644
src: ttl.conf.j2
register: ttl_config
notify:
- Restart unbound
- name: Start unbound
become: yes
service:
name: unbound
state: started
enabled: yes