I’m unsure why you need to pass a groupname to your custom script, unless I am misunderstanding your use of groupname in this context. You can return structured JSON that groups hosts automatically, which you can then use in the ‘hosts’ specification in a playbook with ansible-playbook or from the command line with the ansible command.
However, with that aside, there are ways to get data from the command line into your inventory script. Many of the current inventory scripts do this using environment variables. An example would look like: GROUP=foo ansible-playbook -i /path/to/my/inventory.py playbook.yml Then in your custom inventory script, you would utilize something like: os.getenv(‘GROUP’) I do know for one that the rax.py inventory script does this with RAX_CREDS_FILE as well as RAX_REGION -- Matt Martz [email protected] On December 12, 2013 at 5:34:34 PM, E.C. Raymond ([email protected]) wrote: Hi James, I have checked out the document before, but I am under the impression that I am not able to pass a group to my custom inventory script through the ansible command without making modifications to the ansible inventory modules. The database we have already organizes our hosts by role and returns the list of hostnames. I only need to pass the groupname to my inventory script. This doesn't seem available without making modifications. On Thursday, December 12, 2013 3:09:24 PM UTC-8, James Tanner wrote: We have a nice guide for developing external inventory scripts: http://www.ansibleworks.com/docs/developing_inventory.html The key piece for your question: "When the external node script is called with the single argument ‘–list’, the script must return a JSON hash/dictionary of all the groups to be managed." On Dec 12, 2013, at 5:53 PM, E.C. Raymond <[email protected]> wrote: We have a database that is populated with host and group information. I have searched through various documents on the ansible site and looked at the inventory plugins, but I am not sure how to implement what I need. We currently have a custom lookup script that does what we need, so I am just trying to pass a call to this from ansible. example: # hostlookup role dbservers db1 db2 db3 I want to be able to pass the "dbservers" role/group to my custom inventory script. # ansible -i lookup.py dbservers -m ping I am unclear on what sys.argv/argument ansible passes, on how to get this passed to an internal function for my custom inventory script. Thanks. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
