Currently, all scripts for dynamic inventory are expected to return all hosts that are only wanted using two passed arguments: --list and --host. There is no way from ansible, ansible-playbook, the base API or others to specify the criteria for which the host of the inventory are to be made dynamically against.
Use cases and examples.
-
For cloud based inventories, we have to find a way to tell the scripts what regions to pull servers from. This is done through the script configuration and environmental variables.
-
If you run a large enterprise where you want to deploy one controller for many organizational units that you run, separated into customer or account numbers and separate devices in each configuration.
-
Managing thousands of hosts, in these same ways, concepts of configuration of the script have to be accounted to cut down on the number of API calls we make.
Instead, we should be able to also pass a --script-search argument, allowing this extra information to be sent to and parsed by the end script. This is meant to be ambiguous, optional, and left up to the developer of the resulting dynamic inventory script to do with as they please. As it stands, we either have to account for this through outside script and Ansible interactions, or rely on returning all the data possible from a script, and parsing our host within Ansible using patterns and subsets. Adding the additional argument, we could do the following.
- For cloud inventories we could now then pass a geographic region that the script will only retrieve the hosts needed: ansible -i cloud.py --script-search US -m ping web
- For a large enterprise with multiple business units, customers and devices, this will allow the script only to call and retrieve the needed host: ansible -i MyCompany.py --script-search “customer=1234 BU=small” -m ping mysql-server
- For managing thousands of host, we can cut the API cost down by specifying the criteria -before- delivering to Ansible: ansible -i company.py --script-search stagingEast -m ping webheads
This allows for easier maintainability of our dynamic inventories, cuts down on the cost they cause on the external systems and makes for a better fit in existing automated systems or configurations. We already have completed changes in the inventory code, ansible and ansible-playbook for this, and in testing in our environment the results are exactly as expected. I am seeking interest to have this feature and code review to submit the pull request if wanted.
Also any thoughts or questions are welcome!