ansible/roles/dns/tasks/main.yml
2024-09-08 11:29:34 +02:00

95 lines
2 KiB
YAML

- name: Generate zone var
set_fact:
zones: |
{%- set r = [] -%}
{%- for z in zone_list -%}
{%- set rec = [] -%}
{%- for h in groups['all'] -%}
{%- if z.name == h[-(z.name|length):] and 'ansible_host' in hostvars[h] -%}
{%- set _ = rec.append({
"name": h,
"ip": hostvars[h]['ansible_host']
}) -%}
{%- for c in hostvars[h]['cname']|default([]) -%}
{%- set _ = rec.append({
"name": c,
"ip": h + ".",
"type": "CNAME"
}) -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- set _ = r.append({
"name": z.name,
"records": rec
}) -%}
{%- endfor -%}
{{ r }}
when: dns_local
- name: Install bind
apt:
pkg:
- bind9
- bind9-utils
- ldnsutils
update_cache: true
- name: Create zones directory
file:
path: /etc/bind/master
state: directory
owner: bind
group: bind
mode: 0755
notify: Restart bind9
- name: Create named.conf
template:
src: named.conf.j2
dest: /etc/bind/named.conf
notify: Restart bind9
- name: Create named.conf.local
template:
src: named.conf.local.j2
dest: /etc/bind/named.conf.local
notify: Restart bind9
- name: Create named.conf.options
template:
src: named.conf.options.j2
dest: /etc/bind/named.conf.options
notify: Restart bind9
- name: Create log directory
file:
path: /var/log/named
state: directory
owner: bind
group: bind
mode: 0755
notify: Restart bind9
- name: Create zone files
template:
src: db.j2
dest: "/etc/bind/master/{{ item.name }}.db"
mode: 0644
owner: bind
group: bind
loop: "{{ zones|default(zone_list) }}"
notify: Restart bind9
- name: Remove journal zone files
file:
path: "/etc/bind/master/{{ item.name }}.db.jnl"
state: absent
loop: "{{ zones|default(zone_list) }}"
notify: Restart bind9
# - name: Create reverse zone files
- name: Check configuration integrity
shell: "named-checkconf -zj /etc/bind/named.conf"
register: check1