community.dns.lookup_as_dict lookup – Look up DNS records as dictionaries
Note
This lookup plugin is part of the community.dns collection (version 3.1.0).
You might already have this collection installed if you are using the ansible
package.
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 community.dns
.
You need further requirements to be able to use this lookup plugin,
see Requirements for details.
To use it in a playbook, specify: community.dns.lookup_as_dict
.
New in community.dns 2.6.0
Synopsis
Look up DNS records and return them as interpreted dictionaries.
Requirements
The below requirements are needed on the local controller node that executes this lookup.
dnspython >= 1.15.0 (maybe older versions also work)
ipaddress (on Python 2.7 when using
server
)
Terms
Parameter |
Comments |
---|---|
Domain name(s) to query. |
Keyword parameters
This describes keyword parameters of the lookup. These are the values key1=value1
, key2=value2
and so on in the following
examples: lookup('community.dns.lookup_as_dict', key1=value1, key2=value2, ...)
and query('community.dns.lookup_as_dict', key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
How to handle NXDOMAIN errors. These appear if an unknown domain name is queried.
Choices:
|
|
Number of retries for DNS query timeouts. Default: |
|
Timeout per DNS query in seconds. Default: |
|
If If Note that this behavior changed in community.dns 3.0.0. In community.dns 2.x.y, Choices:
|
|
The DNS server(s) to use to look up the result. Must be a list of one or more IP addresses. By default, the system’s standard resolver is used. |
|
How often to retry on SERVFAIL errors. Default: |
|
The record type to retrieve. Choices:
|
Notes
Note
When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
lookup('community.dns.lookup_as_dict', term1, term2, key1=value1, key2=value2)
andquery('community.dns.lookup_as_dict', term1, term2, key1=value1, key2=value2)
Note that when using this lookup plugin with
lookup()
, and the result is a one-element list, Ansible simply returns the one element not as a list. Since this behavior is surprising and can cause problems, it is better to usequery()
instead oflookup()
. See the examples and also Forcing lookups to return lists in the Ansible documentation.
Examples
- name: Look up A (IPv4) records for example.org as a list of dictionaries
ansible.builtin.debug:
msg: "{{ query('community.dns.lookup_as_dict', 'example.org.') }}"
- name: Look up AAAA (IPv6) records for example.org as a list of IPv6 addresses
ansible.builtin.debug:
msg: "{{ query('community.dns.lookup_as_dict', 'example.org.', type='AAAA' ) | map(attribute='address') }}"
- name: Look up TXT records for ansible.com as a list of strings
ansible.builtin.debug:
msg: "{{ query('community.dns.lookup_as_dict', 'ansible.com.', type='TXT' ) | map(attribute='value') }}"
Return Value
Key |
Description |
---|---|
The records of type If multiple DNS names are queried in Depending on For Returned: success Sample: |
|
The algorithm ID. Returned: if |
|
The altitude. Returned: if |
|
The certificate. Returned: if |
|
The CPU. Returned: if |
|
The digest. Returned: if |
|
The digest’s type. Returned: if |
|
The exchange server. Returned: if |
|
The expiration Unix timestamp. Returned: if |
|
Number of seconds after which secondary name servers should stop answering request for this zone if the main name server does not respond. Returned: if |
|
The fingerprint. Returned: if |
|
Flags. This is actually of type Returned: if |
|
The fingerprint’s type. Returned: if |
|
The horizontal precision of the location. Returned: if |
|
The inception Unix timestamp. Returned: if |
|
The number of iterations. Returned: if |
|
The key. Returned: if |
|
The key’s tag. Returned: if |
|
The labels. Returned: if |
|
The location’s latitude. Returned: if |
|
The location’s longitude. Returned: if |
|
The mbox. Returned: if |
|
Used to calculate the TTL for purposes of negative caching. Returned: if |
|
Primary main name server for this zone. Returned: if |
|
The mtype. Returned: if |
|
The next value. Returned: if |
|
The order value. Returned: if |
|
The original TTL. Returned: if |
|
The operating system. Returned: if |
|
The port. Returned: if |
|
The preference value for this record. Returned: if |
|
The priority value for this record. Returned: if |
|
The protocol. Returned: if |
|
Number of seconds after which secondary name servers should query the main name server for the SOA record to detect zone changes. Returned: if |
|
A regular expression. Returned: if |
|
The replacement. Returned: if |
|
Number of seconds after which secondary name servers should retry to request the serial number from the main name server if the main name server does not respond. Returned: if |
|
E-mail address of the administrator responsible for this zone. Returned: if |
|
The salt. Returned: if |
|
The selector. Returned: if |
|
Serial number for this zone. Returned: if |
|
The service. Returned: if |
|
The signature. Returned: if |
|
The signer. Returned: if |
|
The size of the location. Returned: if |
|
List of strings for this record. See |
|
The tag. Returned: if |
|
The target. Returned: if |
|
The TXT value. Returned: if |
|
The type covered. Returned: if |
|
The usage flag. Returned: if |
|
The vertical precision of the location. Returned: if |
|
The service’s weight. Returned: if |
|
The windows. Returned: if |