Helps to get ansible dynamic inventory from MongoDB
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.
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"
}
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
]
}
python3 -m pip install pymongo
Add mongo.py file in your hosts
directory or set it as a inventory directly via ansible-playbook your_playbook.yml -i mongo.py