Skip to content

TrueWebApp/mongodb-inventory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Ansible dynamic inventory for MongoDB

Helps to get ansible dynamic inventory from MongoDB

How to use

1. Set environment variables

INV_MONGO_URI - Mongo uri with all required credentials.

INV_MONGO_DB - Mongo inventory database.

INV_INCLUDE_META - [optional] Set to include hosts _meta to inventory. Otherwise ansible will request host data one by one.

2. Create collections groups and hosts

Group object example:

{
    "name": "group_name",
    "children": [
        "child_group_1",
        "child_group_2"
    ],
    "hosts": [
        "192.168.28.71",
        "dns.google.com"
    ],
    "vars": {
        "ansible_ssh_user": "no_root",
        "ansible_ssh_private_key_file": "~/.ssh/root_key",
        "is_foo": True,
        "bar_qty": 123
    }
}

Host object example:

{
    "name": "dns.google.com",
    "ansible_host": "8.8.8.8",
    "foo": "bar"
}

3. Is it default inventory?

To replace default inventory just add groups all and ungrouped to your mongo inventory.

{
    "name" : "all",
    "children" : ["ungrouped"],  # don't forget to add other high-level groups here
    "vars" : {}
}
{
    "name" : "ungrouped",
    "children" : [],
    "hosts" : [
        # names of all ungrouped hosts
    ]
}

4. Install pymongo

python3 -m pip install pymongo

5. Enable script

Add mongo.py file in your hosts directory or set it as a inventory directly via ansible-playbook your_playbook.yml -i mongo.py

Done :)

About

Helps to get ansible dynamic inventory from MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages