ansible.windows.win_dns_record module – Manage Windows Server DNS records

Note

This module is part of the ansible.windows collection (version 3.9.1).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install ansible.windows. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: ansible.windows.win_dns_record.

New in ansible.windows 2.6.0

Synopsis

  • Manage DNS records within an existing Windows Server DNS zone.

Requirements

The below requirements are needed on the host that executes this module.

  • This module requires Windows 8, Server 2012, or newer.

Parameters

Parameter

Comments

aging

boolean

Should aging be activated for the record.

If set to false, the record will be static.

Choices:

  • false ← (default)

  • true

allow_update_any

boolean

added in ansible.windows 3.5.0

Specifies if any authenticated user can update the record.

Applies when creating a record. Changing this option does not modify permissions on an existing record.

If set to true, any authenticated user can update the record.

If set to false, only the account that created the record or accounts with appropriate permissions can update it.

For non-SRV records, this was previously hardcoded to true. Since ansible.windows>=3.5.0 it now defaults to false to ensure records are secure by default.

Choices:

  • false ← (default)

  • true

computer_name

string

Specifies a DNS server.

You can specify an IP address or any value that resolves to an IP address, such as a fully qualified domain name (FQDN), host name, or NETBIOS name.

The execution host requires the DnsServer PowerShell module and permission to manage records on this server.

When using WinRM through another host, configure authentication that permits access to the DNS server.

name

string / required

The record owner, relative to zone, or its fully qualified name within that zone.

A matching zone suffix is removed before querying or modifying the record.

Use @ or the zone’s fully qualified name for a record at the zone apex.

An absolute name ending in a period must belong to zone.

port

integer

The port number of the record.

Required when type=SRV.

Supported only for type=SRV.

Valid range is 0 - 65535.

priority

integer

The priority number for each service in SRV record.

Required when type=SRV.

Supported only for type=SRV.

Valid range is 0 - 65535.

state

string

Whether the record should exist or not.

Choices:

  • "absent"

  • "present" ← (default)

ttl

integer

The “time to live” of the record, in seconds.

Ignored when state=absent.

Valid range is 1 - 31557600.

Default: 3600

type

string / required

The type of DNS record to manage.

SRV was added in the 1.0.0 release of this collection.

NS was added in the 1.1.0 release of this collection.

TXT was added in the 1.6.0 release of this collection.

DHCID was added in the 1.12.0 release of this collection.

Choices:

  • "A"

  • "AAAA"

  • "CNAME"

  • "DHCID"

  • "NS"

  • "PTR"

  • "SRV"

  • "TXT"

value

aliases: values

list / elements=string

The value(s) to specify. Required when state=present.

For type=PTR, supply the target host name here and the partial IP address in name.

Multiple values can be supplied for record types that permit multiple records at the same owner.

Default: []

weight

integer

Weightage given to each service record in SRV record.

Required when type=SRV.

Supported only for type=SRV.

Valid range is 0 - 65535.

zone

string / required

The name of the zone to manage (eg example.com).

The zone must already exist.

zone_scope

string

The name of the zone scope to manage (eg ScopeAZ).

The zone must already exist.

See Also

See also

ansible.windows.win_dns_record_info

Get Windows Server DNS records.

ansible.windows.win_dns_zone

Manage Windows Server DNS Zones.

Examples

# Demonstrate creating a matching A and PTR record.

- name: Create database server record
  ansible.windows.win_dns_record:
    name: "cgyl1404p"
    type: "A"
    value: "10.1.1.1"
    zone: "amer.example.com"

- name: Create matching PTR record
  ansible.windows.win_dns_record:
    name: "1.1.1"
    type: "PTR"
    value: "db1"
    zone: "10.in-addr.arpa"

# Demonstrate replacing an A record with a CNAME

- name: Remove static record
  ansible.windows.win_dns_record:
    name: "db1"
    type: "A"
    state: absent
    zone: "amer.example.com"

- name: Create database server alias
  ansible.windows.win_dns_record:
    name: "db1"
    type: "CNAME"
    value: "cgyl1404p.amer.example.com"
    zone: "amer.example.com"

# Demonstrate creating multiple A records for the same name

- name: Create multiple A record values for www
  ansible.windows.win_dns_record:
    name: "www"
    type: "A"
    values:
      - 10.0.42.5
      - 10.0.42.6
      - 10.0.42.7
    zone: "example.com"

# Demonstrates a partial update (replace some existing values with new ones)
# for a pre-existing name

- name: Update www host with new addresses
  ansible.windows.win_dns_record:
    name: "www"
    type: "A"
    values:
      - 10.0.42.5  # this old value was kept (others removed)
      - 10.0.42.12  # this new value was added
    zone: "example.com"

# Demonstrate creating a SRV record

- name: Creating a SRV record with port number and priority
  ansible.windows.win_dns_record:
    name: "test"
    priority: 5
    port: 995
    state: present
    type: "SRV"
    weight: 2
    value: "amer.example.com"
    zone: "example.com"

# Demonstrate creating a NS record with multiple values

- name: Creating NS record
  ansible.windows.win_dns_record:
    name: "ansible.prog"
    state: present
    type: "NS"
    values:
      - ns1.example.com
      - ns2.example.com
    zone: "example.com"

# Demonstrate creating a TXT record

- name: Creating a TXT record with descriptive Text
  ansible.windows.win_dns_record:
    name: "test"
    state: present
    type: "TXT"
    value: "justavalue"
    zone: "example.com"

# Demostrate creating a A record to Zone Scope

- name: Create database server record
  ansible.windows.win_dns_record:
    name: "cgyl1404p"
    type: "A"
    value: "10.1.1.1"
    zone: "amer.example.com"
    zone_scope: "external"

Authors

  • Sebastian Gruber (@sgruber94)

  • John Nelson (@johnboy2)