Hi Matt,

I appreciate your help, and I do understand what you are explaining.  My 
inventory script does not return all my hosts with all respective groups. 
 This is a limitation based on the number of hosts and how the api outputs 
a query on our end.  I understand that ansible expects the inventory to 
return all hosts, but I was trying to circumnavigate the ansible call, and 
be able to pass through the group from the command arguments to get only a 
limited number of hosts.

Thanks again.

On Friday, December 13, 2013 9:39:33 AM UTC-8, Matt Martz wrote:
>
> I really do believe you are missing what we are saying.  Either that or I 
> am just uber confused about what you are doing that we are not providing 
> you with an explanation for.
>
> You do not need to limit the output of the inventory script itself, you do 
> that filtering with the ansible/ansible-playbook commands. Your inventory 
> should return *all* groups and hosts.  The ansible and ansible-playbook 
> commands offer the ability to filter the list of groups/hosts that you want 
> to run the tasks on.
>
> Then you would so something like:
>
> ansible webserver -i /path/to/inventory.py -m ping
>
> In that example, the 2nd argument there is the group you are targeting, or 
> it can be a host, a pattern...
>
> or 
>
> ansible-playbook -i /path/to/inventory.py --limit web server my-playbook.py
>
> In this example --limit allows you to limit to a group, or hosts, etc… 
> that you want to target
>
>
> Also note that the ansible command also offers -l/--limit
>
> You might want to look at 
> http://www.ansibleworks.com/docs/intro_adhoc.html also
>
> -- 
> Matt Martz
> [email protected] <javascript:>
>
> On December 13, 2013 at 11:29:39 AM, E.C. Raymond 
> ([email protected]<javascript:>) 
> wrote:
>
> Thanks for all the help everyone.  The GROUP os env variable being passed 
> just makes for a confusing simple one-liner call.  I was hoping to find 
> something similar to how saltstack can do a in-line list call with -L: salt 
> -L web1,web2,web3 test.ping 
>
> I guess I will put that in as a feature request.
>
> On Thursday, December 12, 2013 5:07:22 PM UTC-8, Matt Martz wrote: 
>>
>>  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] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> 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].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to