alexisfacques.ansible_module_dig

ansible-module-dig

ansible-module-dig is a custom Ansible module that allows you to perform DNS lookups from remote Ansible hosts. It returns a list of resolved IPv4 addresses for each name. The dig module can also check the hosts' /etc/hosts file before doing any lookup.

You can use this module to:

  • resolve one or more hostnames.
  • check if one or more hostnames can be resolved (the module will fail if it cannot resolve a hostname to at least one address).

dig module vs. Ansible lookup('dig', ... )

Be careful when using this module! The official method for DNS lookups in Ansible is through the dig lookup.

The main problem with lookup filters, like other templates, is that they are evaluated on the Ansible control machine, not the target host. This can lead to unexpected results in complex networking environments where the control machine can resolve all hosts, but the target hosts cannot (for example, when running configuration plays through an external network or in secure environments).

The Ansible dig module solves this issue by performing lookups directly from the remote hosts.

Getting Started

Requirements

The following requirements must be met on the host that runs this module:

  • dnspython for Python.

Installing

Using Ansible role

  • Clone this repository to your Ansible role_path, or install it using ansible-galaxy:
    ansible-galaxy install alexisfacques.ansible_module_dig
    
  • Import the role in your playbooks before running any task that requires the dig module:
    - hosts: all
      roles:
        - alexisfacques.ansible_module_dig
      tasks:
        - name: Ensure google.com can be resolved
          dig:
            qtype: A
            name: google.com
          register: dig_result
    

Using Ansible library

If using a role is too complex, you can place this module in the library directory defined in your ansible.cfg file (the default is a sub-directory called library in your playbook directory):

[defaults]
library = /path/to/your/library

Usage

Parameters

Parameter Choices/Defaults Comments
qtype Default: A Specifies the type of query: ANY, A, MX, SIG... Any valid query type.
name string list / required
nameserver string list
with_etc_hosts Choice: true false
Default: true

Return Values

Key Returned Description
addresses On success if all names resolved to at least one IPv4 address. A 2D array of IPv4 addresses corresponding to each looked-up name.

Example of Use

You can find examples of usage here.

Acknowledgments

License

This project is licensed under the MIT License. See the LICENSE file for details.

Informazioni sul progetto

DNS lookups in Ansble (on remote host) made easy.

Installa
ansible-galaxy install alexisfacques.ansible_module_dig
Licenza
mit
Download
313
Proprietario
🔵⚪️