bertvv / ansible-role-bind

Sets up ISC BIND as an authoritative DNS server on several Linux distros & FreeBSD
https://galaxy.ansible.com/bertvv/bind/
Other
255 stars 183 forks source link

Create forward lookup zone file: AnsibleUndefinedVariable: 'dict object' has no attribute 'serial' #183

Open ruan-dt opened 2 years ago

ruan-dt commented 2 years ago

Short error output:

TASK [bertvv.bind : Create forward lookup zone file] ***************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'serial'
failed: [hostname] (item=domain.name) => {"ansible_loop_var": "item", "changed": false, "item": {"create_reverse_zones": true, "hosts": [{"aliases": ["a1", "a2", "a3"], "ip": "172.20.8.1", "name": "gateway"}, {"aliases": ["b1"], "name": "somewhere.else."}], "name": "domain.name", "name_servers": ["gateway.domain.name."], "primaries": ["172.20.8.1"], "type": "primary"}, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'serial'"}

Running with -vvv didn't obviously turn up anything more useful, but I can add that output if needs be.

Is this me doing something wrong? Having only been using ansible for a few weeks, and lacking supervision, I can't really tell myself.

blofeldthefish commented 2 years ago

Hi @ruan-dt

Can you provide the playbook you were using with this role, and it will provide more insight as to what your particular issue is.

We can then look at closer....

ruan-dt commented 2 years ago

@blofeldthefish so, finally having a little time to get back to this again:

Minimal host file:

host0 field_subnet="172.20.4.0/22"
host1 field_subnet="172.20.8.0/22"

Minimal playbook:

- name: configure hosts
  hosts:
   - host0
   - host1

  vars:
    field_ip: "{{ field_subnet | ansible.netcommon.ipaddr('net') | ansible.netcommon.ipaddr('1') | ansible.netcommon.ipaddr('address') }}"

  roles:
    - role: bertvv.bind
      become: yes

      # if this is missing, the version of bind on ubuntu 22.04 will raise a grumpy 
      # "option 'dnssec-enable' no longer exists" error.
      bind_dnssec_enable: false

      bind_zones:
        - name: "{{ site_name }}"
          type: primary
          primaries:
            - "{{ field_ip }}"
          name_servers:
            - "gateway."
          hosts:
            - name: gateway
              ip: "{{ field_ip }}"
patrickstump commented 2 years ago

Can confirm this issue. Not sure why, but it works fine on the first server in the group, but not for the following servers.

For example is hosts: group_name vs hosts: server.domain.name. Originally i thought the issue was that the serial is only calculated as a run_once at tasks/main.yml line 78.

- name: Create serial, based on UTC UNIX time
  command: date -u +%s
  register: timestamp
  changed_when: false
  run_once: true
  check_mode: false
  tags: bind

However, I am not sure now. I tried modifying the serial and removing the run once and it kept happening.

patrickstump commented 2 years ago

Ok. Have it working. The issue appears to be not only that timestamp was created for only one host. It could actually deal with that in the zone template.

The main issue is that the hash'es for the zone files were not being calculated on any other host after the first one. Which causes the issue in the zone template. My workaround atm is to change all the zone hash tasks in tasks/zones.yml with run once to false. And it works fine.

Not sure how this will affect non primary nameservers, as I am not running them that way.

chrisisbeef commented 1 year ago

Is there a fix for this issue short of forking the repository and getting rid of run_once on those tasks?