summaryrefslogtreecommitdiff
path: root/roles/network/bind/tasks/main.yml
blob: 34e417db9b517e9be8962aca8e36b5c95cc60faa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
- name: install bind
  apt:
    name: bind9
    state: present

- name: set bind options
  blockinfile:
    path: /etc/bind/named.conf.options
    block: |
      {% if bind_option_empty_zones_enable is defined %}
              empty-zones-enable {% if bind_option_empty_zones_enable %}yes{% else %}no{% endif %};
      {% endif %}
      {% if bind_option_allow_query is defined %}

              allow-query {
      {%   for item in bind_option_allow_query %}
                      {{ item }};
      {%   endfor %}
              };
      {% endif %}
      {% if bind_option_allow_recursion is defined %}

              allow-recursion {
      {%   for item in bind_option_allow_recursion %}
                      {{ item }};
      {%   endfor %}
              };
      {% endif %}
      {% if bind_option_allow_update is defined %}

              allow-update {
      {%   for item in bind_option_allow_update %}
                      {{ item }};
      {%   endfor %}
              };
      {% endif %}
      {% if bind_option_notify is defined %}

              notify {{ bind_option_notify }};
      {% endif %}
      {% if bind_option_also_notify is defined %}

              also-notify {
      {%   for item in bind_option_also_notify %}
                      {{ item }};
      {%   endfor %}
              };
      {% endif %}
      {% if bind_option_allow_transfer is defined %}

              allow-transfer {
      {%   for item in bind_option_allow_transfer %}
                      {{ item }};
      {%   endfor %}
              };
      {% endif %}
    insertbefore: '};'
    marker: "        // {mark} ansible managed block"
  notify: reload bind


- name: add zone blacklist config
  copy:
    dest: "/etc/bind/named.conf.blacklist"
    content: |
      {% for zone in bind_zone_blacklist %}
      zone "{{ zone }}" {
              type master;
              file "/etc/bind/db.empty";
              zone-statistics no;
              notify no;
      };
      {% endfor %}
  notify: reload bind

- name: enable zone backlist
  lineinfile:
    path: /etc/bind/named.conf
    line: 'include "/etc/bind/named.conf.blacklist";'
    state: present
  notify: reload bind


- name: add stats configuration
  when: bind_stats_channels is defined
  template:
    src: stats.j2
    dest: /etc/bind/named.conf.stats
  notify: reload bind

- name: remove stats configuration
  when: bind_stats_channels is not defined
  file:
    path: /etc/bind/named.conf.stats
    state: absent
  notify: reload bind

- name: enable/disable stats configuration
  lineinfile:
    path: /etc/bind/named.conf
    line: 'include "/etc/bind/named.conf.stats";'
    state: "{{ bind_stats_channels is defined | ternary('present', 'absent') }}"
  notify: reload bind


- name: add slave zone configuration
  when: bind_slave_zones is defined
  template:
    src: slave-zones.j2
    dest: /etc/bind/named.conf.slave-zones
  notify: reload bind

- name: remove slave zone configuration
  when: bind_slave_zones is not defined
  file:
    path: /etc/bind/named.conf.slave-zones
    state: absent
  notify: reload bind

- name: enable/disable slave zone configuration
  lineinfile:
    path: /etc/bind/named.conf
    line: 'include "/etc/bind/named.conf.slave-zones";'
    state: "{{ bind_slave_zones is defined | ternary('present', 'absent') }}"
  notify: reload bind


- name: add master zone configuration
  when: bind_master_zones is defined
  template:
    src: master-zones.j2
    dest: /etc/bind/named.conf.master-zones
  notify: reload bind

- name: remove master zone configuration
  when: bind_master_zones is not defined
  file:
    path: /etc/bind/named.conf.master-zones
    state: absent
  notify: reload bind

- name: install master zone files (from local file)
  when: bind_master_zones is defined
  loop: "{{ bind_master_zones | dict2items | selectattr('value.file', 'defined') | list }}"
  loop_control:
    label: "{{ item.key }}"
  copy:
    dest: "/etc/bind/db.{{ item.key }}"
    src: "{{ item.value.file }}"
  notify: reload bind

- name: install master zone files (from content)
  when: bind_master_zones is defined
  loop: "{{ bind_master_zones | dict2items | selectattr('value.content', 'defined') | list }}"
  loop_control:
    label: "{{ item.key }}"
  copy:
    dest: "/etc/bind/db.{{ item.key }}"
    content: "{{ item.value.content }}"
  notify: reload bind

- name: enable/disable master zone configuration
  lineinfile:
    path: /etc/bind/named.conf
    line: 'include "/etc/bind/named.conf.master-zones";'
    state: "{{ bind_master_zones is defined | ternary('present', 'absent') }}"
  notify: reload bind