All Projects → mattkeeler → ansible-dns-inventory

mattkeeler / ansible-dns-inventory

Licence: other
A dynamic inventory script for Ansible that uses DNS TXT records

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to ansible-dns-inventory

yaani
Yet another Ansible Netbox inventory
Stars: ✭ 12 (-40%)
Mutual labels:  ansible-inventory
simple-ansible-inventory
A simple, clean and easily readable Ansible inventory
Stars: ✭ 25 (+25%)
Mutual labels:  ansible-inventory
itop-utilities
Utilities scripts for itop, an open source cmdb. Empowers CMDB by connecting it to other system like Ansible.
Stars: ✭ 38 (+90%)
Mutual labels:  ansible-inventory
ansible-pull-example
example skeleton repo for setting up ansible-pull infrastructure
Stars: ✭ 22 (+10%)
Mutual labels:  ansible-inventory
Ansible-inventory-file-examples
Examples and counter-examples of Ansible inventory files
Stars: ✭ 25 (+25%)
Mutual labels:  ansible-inventory
ansible-nutanix-inventory
A dynamic inventory script for Ansible that interacts with the Nutanix API
Stars: ✭ 23 (+15%)
Mutual labels:  ansible-inventory
ansible-ssh
Script to connect to managed hosts using Ansible inventory and config.
Stars: ✭ 51 (+155%)
Mutual labels:  ansible-inventory
ansible-yaml inventory
Ansible dynamic inventory reading the inventory from YAML file.
Stars: ✭ 19 (-5%)
Mutual labels:  ansible-inventory

Ansible DNS dynamic inventory script

Overview

This Python script, based upon Remie Bolte's Node.js script to the same purpose, generates a dynamic inventory from specially formatted DNS TXT records. Output is in JSON.

It works by querying the specified domain for any TXT records matching two types of strings. The first specifies a hostname and any groups that host belongs to, using the following format:

 "hostname=tomcat01.example.com;groups=tomcat,webserver,texas"

Hosts without any specified groups will be added to the "ungrouped" group

The second string specifies any group_vars for a given group:

"group=webserver;vars=foo_var:foo,bar_var:bar"

You can also use subgroups (children):

"group=dbservers;children=mysqlservers,pgservers,oraservers"

And a subgroup (child) can have a group variable too:

"group=pgservers;vars=foo_var:foo,bar_var:bar"

You can optionally specify host_vars on a hostname line, like so:

 "hostname=mysql.example.com;hostvars=foo_var:foo,bar_var:bar"
 "hostname=lab3.example.com;groups=lab;hostvars=foo_var:foo"

If you want a variable to be an array of values:

"group=webserver;vars=foo_var:[bar1|bar2|bar3]"

Output might look something like this:

{
    "_meta": {
        "hostvars": {
            "mysql.example.com": {
                "foo_var": "foo",
                "bar_var": "bar"
            }
        }
    },
    "tomcat": {
        "hosts": [
            "tomcat01.example.com",
            "tomcat02.ptsteams.lab"
        ]
    },
    "lab": {
        "hosts": [
            "lab1.example.com"
            "lab2.example.com"
            "lab3.example.com"
        ],
        "vars": {
            "ansible_port": "22",
            "ansible_user": "matt"
        }
    },
    "ungrouped": {
        "hosts": [
            "mysql.example.com"
        ]
    },
    "webservers": {
        "hosts": [
            "webserver1.example.com"
            "webserver2.example.com"
        ]
    }
}

Some things to keep in mind:

  1. In an inventory, host_vars take precedence over group_vars.

  2. Child group_vars take precedence over group_vars (and are not merged)

  3. Strings in TXT records are limited to 255 characters, but an individual record can be composed of multiple strings enclosed in double quotation marks and separated by a space. Per RFC 4408 and RFC 1035, this script treats multiple strings as if they are concatenated together. So a TXT record like

      "group=db;vars=ansible_port:22" ",bar_var:bar"
    

    will be read as

    group=db;vars=ansible_port:22,bar_var:bar
    
  4. DNS propagation can take time, as determined by a record's TTL value.

  5. Do not to list sensitive information in TXT records.

  6. You can get a listing of TXT records with: dig +short -t TXT example.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].