GithubHelp home page GithubHelp logo

alexisfacques / ansible-module-dig Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 5 KB

A custom module that allows you to run some DNS lookup on Ansible executing hosts easily.

License: MIT License

Python 100.00%
ansible custom-ansible ansible-role ansible-module dns-lookups lookup-operation dig hostname lookup

ansible-module-dig's Introduction

ansible-module-dig

ansible-module-dig is a custom Ansible module allowing you to run DNS lookup operations from remote Ansible hosts, and returns a list of the resolved IP(v4) addresses per name. The dig module may also be configured to parse the hosts' /etc/hosts file before performing any lookup operation.

This module can thus be used to both:

  • resolve one or multiple hostname(s);
  • assert whether or not one or multiple hostname(s) can be resolved (module will fail if a hostname cannot be resolved to at least one address).

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

Make sure to know what you're doing before using this module! The official way for running DNS lookups in Ansible is by using the dig lookup.

Main issue using lookup filters, like all templating, is that it is evaluated on the Ansible control machine, and not the targeted host. This could cause unexpected side effects when running your Ansible plays in complex networking environments or deployment scenarios, where your control machine can resolve all hosts of your cluster, but hosts cannot (e.g., running your configuration plays through an external management network or in offline or highly secured network environments).

This Ansible dig module fills this gap by executing lookups from the remote hosts directly.

Getting started

Requirements

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

  • dnspython for Python.

Installing

The "Ansible role" way

  • Clone this repository to your Ansible role_path, or install via ansible-galaxy;
    ansible-galaxy install alexisfacques.ansible_module_dig
  • Import the role in your playbooks before running any role or task that require 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

The "Ansible library" way

Alternatively, if importing a role is too much of a hassle, you can store this module in the library directory defined in your ansible.cfg file (Default is a sub-directory called library in the directory that contains your playbooks):

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

Usage

Parameters

Parameter Choices/Defaults Comments
qtype
Default:
A
Indicates what type of query is required: ANY, A, MX, SIG... Type can be any valid query type.
name
- string | list / required
The name(s) of the resource(s) that is to be looked up.
nameserver
- string | list
The name(s) or IPv4 address(es) of nameserver(s) to use.
with_etc_hosts Choice:
true
false

Default:
true
Whether or not the module should try to resolve the name using the host's /etc/hosts file(s) prior to running any lookup operation.

Return values

Key Returned Description
addresses On success if all names have been resolved to at least 1 IPv4 address. A 2D array of IPv4 addresses to each of the looked up name.

Example of use

Examples of use can be found here.

Acknowlegments

License

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

ansible-module-dig's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bkwin66 teadur

ansible-module-dig's Issues

Invenotry creation?

I have tried it and it works great but one question:

How could I use the output in order to create an invenotry.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.