Closed sidcarter closed 8 years ago
$ ansible -i ./rest_api_inventory.py all --list-hosts
Was this inventory script working before? Is the output valid JSON? (could say, './rest_api_inventory.py --list | python -m json.tool' work without error?)
@alikins it's a new script I created. Hadn't used it before.
And yes, the script spits out valid JSON
$ ./rest_api_inventory.py --list | python -m json.tool | head -5
{
"all": {
"hosts": [
{
"10.45.0.4": {
From what I can see, it is due to your inventory being malformed. Although valid JSON, it does not conform to the ansible requirements for a dynamic inventory output.
I can't see everything you have there, but at minimum, hosts
should just be a list of strings, not a list of dictionaries.
See http://docs.ansible.com/ansible/developing_inventory.html for more information on proper formatting.
@sivel thank you. that fixed it. I'm getting the right output now:
$ ansible -i ./rest_api_inventory.py --list-hosts all | head -4
hosts (88):
10.45.0.4
10.45.16.28
10.45.0.17
I have two followup questions:
$ time ./rest_api_inventory.py --list > /dev/null real 0m1.051s user 0m0.125s sys 0m0.055s
With ansible:
$ time ansible -i ./rest_api_inventory.py --list-hosts all > /dev/null
real 1m9.001s
user 0m10.481s
sys 0m4.793s
2nd question: what's the format for host specific variables? I thought that would be a dict. But the link you shared above does not have an example or direction to go for that.
thanks
Got the answer re: second question - http://tech.aabouzaid.com/2015/10/opsview-as-dynamic-inventory-for-ansible-python.html
Adding the "_meta" dictionary to the output fixed the speed issue. This issue can be closed.
Thank you @alikins and @sivel
ISSUE TYPE
COMPONENT NAME
core - Dynamic Inventory
ANSIBLE VERSION
CONFIGURATION
No additional configuration.
OS / ENVIRONMENT
macOS Sierra 10.12 beta
Same error on CentOS 7.2 too
uname -a Linux 10.0.3.136 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
SUMMARY
Executing an inventory script with ansible throws errors
STEPS TO REPRODUCE
Use inventory script for inventory sources. Inventory script generates out put --list and --host
inventory script:
$ ls -l rest_api_inventory.py -rwxr-xr-x@ 1 sidcarter staff 3184 Sep 6 19:43 rest_api_inventory.py
e.g.:
When run with ansible, it should show list of hosts.
EXPECTED RESULTS
ACTUAL RESULTS