When using ansible-playbook, if you *only* wanted to operate on that group and your inventory script can limit it, you basically run it like:
GROUP=webservers ansible-playbook -i /path/to/custom_inventory.py my-playbook.yml In my-playbook.yml you specify “hosts: webservers” or “hosts: all”. Generally, I just wouldn’t limit the output from the inventory script, and let the inventory script return *all* hosts and groups, still with the correct data structure with host groups. >From a one-liner, it would look like: GROUP=webservers ansible webservers -i /path/to/custom_inventory.py -m ping or GROUP=webservers ansible all -i /path/to/custom_inventory.py -m ping In the above one-line examples, using web servers or all would give you the same thing, since you are limiting the response from your inventory script to only the webservers group. If you just returned all hosts and groups, you could skip the GROUP=whatever part and just do something like: ansible webservers -i /path/to/custom_inventory.py -m ping -- Matt Martz [email protected] On December 12, 2013 at 6:49:35 PM, E.C. Raymond ([email protected]) wrote: This is exactly what my inventory/cmdb does already. At the heart of my custom script is basically a call that looks similar to ansibles output, but I also format into a json dictionary: >From custom_inventory.py script, i have a function called get_hosts_by_role >and it looks like: # /usr/local/bin/lookup_hosts group webservers web1 web2 web3 Ansible Inventory plugin: (ans-prod)/srv/ansible$ ./plugins/inventory/custom_inventory.py --list { "webservers": { "hosts": [ "web1", "web2", "web3", "web4" ] } } This works if I use the GROUP="webservers", then os.gentenv('GROUP') and run the custom script manually with --list. But if I were to use a playbook or even a one-liner, how would I specify the group "webservers" and be able to pass that to the inventory or ansible to look up? I feel like I am asking the same question over and over. On Thursday, December 12, 2013 4:15:53 PM UTC-8, Matt Martz wrote: Maybe I am making too much of an assumption here. But generally you would store the host groupings in some way in your custom inventory/cmdb. Then, using that information (hosts + groupings) you return something from your inventory script that looks similar to http://www.ansibleworks.com/docs/developing_inventory.html#id2 where the top level keys of the json response are the groups, that contain a list of hosts. Also, you can have hosts in more than a single group. But from my previous response, if you need to pass info into your inventory, you need to use environment variables. -- Matt Martz [email protected] On December 12, 2013 at 6:03:51 PM, E.C. Raymond ([email protected]) wrote: When I run ansible in one-liner mode: ansible webserver --list-hosts; ansible webserver -m ping How am I able to pass the "webserver" argument to the inventory script? I am not understanding from the documentation and examples of how the execution flow works with ansible and inventory scripts. The documentation seems to indicate that the inventory needs to dump ALL hosts and groups, and then to create a dictionary grouping the host --> group, and then dumps the group and hosts. When running: ./my_custom_inventory --list there is no grouping passed to identify which servers should be stored together. I apologize for the confusing post, but I am just trying to understand how I should pass arguments to my custom api calls and return back something that ansible will understand. The closest I am able to getting something similar to what I want is from the ec2 inventory example. Using the region to help dictate what list to pass into the call to gather the list of hosts. -- 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.
