Skip to content

Improve way to set SOA records #28

@leegarrett

Description

@leegarrett

Currently it's quite difficult to change any SOA value since the serial needs to be read from DNS, and then set in the string. My current approach is this:

[...]
- name: Retrieve current SOA record for example.net
  set_fact:
    soa_serial: "{{ lookup('community.general.dig', 'example.net', qtype='SOA', flat=0)['serial'] }}"

- name: Create example.net SOA records
  inwx.collection.dns:
    session:    "{{ inwx_session }}"
    domain:     "example.net"
    ttl:        86400
    type:       SOA
    value: >-
      {{ mname }}
      {{ rname }}
      {{ soa_serial }}
      {{ refresh }}
      {{ retry }}
      {{ expire }}
      {{ minimum }}
  # https://en.wikipedia.org/wiki/SOA_record
  vars:
    mname:    ns.inwx.de
    rname:    hostmaster.inwx.de
    # don't touch the serial
    refresh:  10800
    retry:    3600
    expire:   604800
    minimum:  60

This has a main problem, though: If previously in the playbook run any other DNS record has been changed, there will be a lag retrieving the serial number for the domain and setting it. Example: a previous task sets an A record for foo.example.net, which bumps the serial in the SOA record to 2025022401. However, due to caching, the lookup task retrieves the old, still cached value of 2025022301. Then the SOA update above ends up setting the serial to a lower value. This of course breaks update propagation to other nameservers.

So the request is simple: Add a new parameter, e.g. "soa_values" that can be set, and any SOA values not set will be read from the existing value. SERIAL will be read, and increased via the usual rules ("YYYYMMDDXX", with a date, and XX increases when needed).

- name: funky new SOA feature
  inwx.collection.dns:
    session:    "{{ inwx_session }}"
    domain:     "example.net"
    ttl:        86400
    type:       SOA
    soa_value:
      minimum:  300 # five minutes is fine

In the above case only the MINIMUM will be changed, with all other values staying the same and SERIAL being increased.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions