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] <javascript:>
>
> On December 12, 2013 at 6:03:51 PM, E.C. Raymond
> ([email protected]<javascript:>)
> 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] <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].
For more options, visit https://groups.google.com/groups/opt_out.