@@ -168,23 +168,30 @@ bind_rndc_client_config:
168168{%- endif % }
169169{% endif % }
170170
171- {% for zone, zone_data in salt[' pillar.get' ](' bind:configured_zones' , {}).items() -% }
171+ {%- set views = {False : salt[' pillar.get' ](' bind' , {})} % }{# process non-view zones in the same loop #}
172+ {%- do views.update(salt[' pillar.get' ](' bind:configured_views' , {})) % }
173+ {%- for view, view_data in views.items() % }
174+ {%- set dash_view = ' -' + view if view else ' ' % }
175+ {% for zone, zone_data in view_data.get(' configured_zones' , {}).items() -% }
172176{%- set file = salt[' pillar.get' ](" bind:available_zones:" + zone + " :file" , false) % }
173177{%- set zone_records = salt[' pillar.get' ](' bind:available_zones:' + zone + ' :records' , {}) % }
174178{# If we define RRs in pillar, we use the internal template to generate the zone file
175179 otherwise, we fallback to the old behaviour and use the declared file
176180# }
177181{%- set zone_source = ' salt://bind/files/zone.jinja' if zone_records != {} else ' salt://' ~ map .zones_source_dir ~ ' /' ~ file % }
178- {% if file and zone_data[' type' ] == " master" -% }
179- zones- {{ zone }}:
182+ {%- set serial_auto = salt[' pillar.get' ](' bind:available_zones:' + zone + ' :soa:serial' , ' ' ) == ' auto' % }
183+ {% if file and zone_data[' type' ] == ' master' -% }
184+ zones{{ dash_view }}- {{ zone }}{{ ' .include' if serial_auto else ' ' }}:
180185 file .managed:
181- - name: {{ map .named_directory }}/ {{ file }}
186+ - name: {{ map .named_directory }}/ {{ file }}{{ ' .include ' if serial_auto else ' ' }}
182187 - source: {{ zone_source }}
183188 - template: jinja
184189 {% if zone_records != {} % }
185190 - context:
191+ zone: zones{{ dash_view }}- {{ zone }}
186192 soa: {{ salt[' pillar.get' ](" bind:available_zones:" + zone + " :soa" ) }}
187193 records: {{ zone_records }}
194+ include: False
188195 {% endif % }
189196 - user: {{ salt[' pillar.get' ](' bind:config:user' , map .user) }}
190197 - group: {{ salt[' pillar.get' ](' bind:config:group' , map .group) }}
@@ -194,36 +201,25 @@ zones-{{ zone }}:
194201 - require:
195202 - file : named_directory
196203
197- {% if zone_data[' dnssec' ] is defined and zone_data[' dnssec' ] -% }
198- signed- {{ zone }}:
199- cmd.run:
200- - cwd: {{ map .named_directory }}
201- - name: zonesigner - zone {{ zone }} {{ file }}
202- - prereq:
203- - file : zones- {{ zone }}
204- {% endif % }
205-
206- {% endif % }
207- {% endfor % }
208-
209- {%- for view, view_data in salt[' pillar.get' ](' bind:configured_views' , {}).items() % }
210- {% for zone, zone_data in view_data.get(' configured_zones' , {}).items() -% }
211- {%- set file = salt[' pillar.get' ](" bind:available_zones:" + zone + " :file" , false) % }
212- {%- set zone_records = salt[' pillar.get' ](' bind:available_zones:' + zone + ' :records' , {}) % }
213- {# If we define RRs in pillar, we use the internal template to generate the zone file
214- otherwise, we fallback to the old behaviour and use the declared file
215- # }
216- {%- set zone_source = ' salt://bind/zone.jinja' if zone_records != {} else ' salt://' ~ map .zones_source_dir ~ ' /' ~ file % }
217- {% if file and zone_data[' type' ] == ' master' -% }
218- zones- {{ view }}- {{ zone }}:
204+ {% if serial_auto % }
205+ zones{{ dash_view }}- {{ zone }}:
206+ module.wait:
207+ - name: dnsutil.serial
208+ - update: True
209+ - zone: zones{{ dash_view }}- {{ zone }}
210+ - watch:
211+ - file : {{ map .named_directory }}/ {{ file }}.include
219212 file .managed:
220213 - name: {{ map .named_directory }}/ {{ file }}
214+ - require:
215+ - module: zones{{ dash_view }}- {{ zone }}
221216 - source: {{ zone_source }}
222217 - template: jinja
223218 {% if zone_records != {} % }
224219 - context:
220+ zone: zones{{ dash_view }}- {{ zone }}
225221 soa: {{ salt[' pillar.get' ](" bind:available_zones:" + zone + " :soa" ) }}
226- records : {{ zone_records }}
222+ include : {{ file }}.include
227223 {% endif % }
228224 - user: {{ salt[' pillar.get' ](' bind:config:user' , map .user) }}
229225 - group: {{ salt[' pillar.get' ](' bind:config:group' , map .group) }}
@@ -232,14 +228,14 @@ zones-{{ view }}-{{ zone }}:
232228 - service: bind
233229 - require:
234230 - file : named_directory
235-
231+ { % endif % }
236232{% if zone_data[' dnssec' ] is defined and zone_data[' dnssec' ] -% }
237- signed- {{ view }}- {{ zone }}:
233+ signed{{ dash_view }}- {{ zone }}:
238234 cmd.run:
239235 - cwd: {{ map .named_directory }}
240236 - name: zonesigner - zone {{ zone }} {{ file }}
241237 - prereq:
242- - file : zones- {{ view }}- {{ zone }}
238+ - file : zones{{ dash_view }}- {{ zone }}
243239{% endif % }
244240
245241{% endif % }
0 commit comments