The task is to generate dns zone files, each zone in a separate file.
Is it possible to somehow complete this task with modules, or will I have to write something of my own?
I'm stuck here:
List with dict:
bind_zones:
- name: "example.com"
file: "example.com.zone"
ttl: 3600
zone_serial: "{{ bind_zone_serial }}"
zone_refresh: 3600
zone_retry: 7200
zone_expire: 3600000
zone_minimum: 3600
records:
- name: "@"
ttl: 3800
class: IN
type: NS
data: ns1
- name: "@"
type: A
data: "192.0.2.1"
- name: "@"
type: AAAA
data: "2001:db8::1"
- name: "www"
type: CNAME
data: "@"
Task:
- name: "Generate zone files"
template:
src: zones.conf.j2
dest: "{{ item.file }}"
owner: root
group: "{{ bind_group }}"
mode: u=rw,g=r,o=r
validate: '{{ bind_bin_path }}named-checkconf -z -j %s'
loop: "{{ bind_zones }}"
Template (but of course the template is broken, just an attempt for example):
{{ ansible_managed | comment(decoration='; ') }}
$ORIGIN {{ bind_zones['name'] }}.
$TTL {{ bind_zones['ttl'] }}
$INCLUDE {{ bind_zones_path }}{{ bind_share_properties_zone_filename }}
{% for record in bind_zones['name']['records'] %}
{{ record['name'] }} {% if record['ttl'] is defined %}{{ record['ttl'] }}{% endif %} {% if record['class'] is defined %}{{ record['class'] }}{% endif %} {{ record['type'] }} {{ record['data'] }}
{% endfor %}
It should work out, each domain in a separate file.