infra/roles/nameservers/tasks/main.yml

50 lines
1.1 KiB
YAML
Raw Normal View History

2024-01-01 20:23:23 -05:00
---
2024-01-02 02:10:54 -05:00
## PRIMARY
2024-01-01 20:23:23 -05:00
- name: create named.conf.local for primary
template:
src: ../templates/named.conf.local.primary.j2
dest: /etc/bind/named.conf.local
2024-01-02 02:10:54 -05:00
owner: bind
group: bind
2024-01-01 20:23:23 -05:00
when: inventory_hostname in groups['dnsprimary']
2024-01-02 02:10:54 -05:00
- name: create /etc/bind/zones if not exist
ansible.builtin.file:
path: /etc/bind/zones
state: directory
owner: bind
group: bind
2024-01-01 20:23:23 -05:00
- name: create primary zone files for primary
template:
2024-01-02 15:42:42 -05:00
src: "../templates/db.{{ item.zone }}.j2"
dest: "/etc/bind/zones/db.{{ item.zone }}"
2024-01-02 02:10:54 -05:00
owner: bind
group: bind
2024-01-01 20:23:23 -05:00
with_items: "{{ dns_zones }}"
when: inventory_hostname in groups['dnsprimary']
2024-01-02 02:10:54 -05:00
## REPLICA
2024-01-01 20:23:23 -05:00
- name: create named.conf.local for replica
template:
src: ../templates/named.conf.local.replica.j2
dest: /etc/bind/named.conf.local
2024-01-02 02:10:54 -05:00
owner: bind
group: bind
2024-01-01 20:23:23 -05:00
when: inventory_hostname in groups['dnsreplica']
2024-01-02 15:42:42 -05:00
- name: flush dns cache on replicas
file: path={{ item }} state=absent
2024-01-04 01:40:27 -05:00
with_fileglob: "/var/cache/bind/db.*"
when: inventory_hostname in groups['dnsreplica']
2024-01-02 15:42:42 -05:00
2024-01-01 20:23:23 -05:00
- name: restart bind9
service:
name: bind9
state: restarted
enabled: true