0

任务是生成 dns zone 文件,每个 zone 在一个单独的文件中。

是否有可能通过模块以某种方式完成此任务,还是我必须自己编写一些东西?

我被困在这里:

用字典列出:

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: "@"

任务:

- 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 }}"

模板(当然模板坏了,只是一个尝试):

{{ 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 %}

它应该可以解决,每个域都在一个单独的文件中。

4

0 回答 0