On Thu, 12 Dec 2013, E.C. Raymond 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:

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?

If your inventory script already provides these groups, you can simply use those groups wherever you are used to mentioning hosts or lists of hosts (in playbooks, on the command-line, ...)

Simply do:

    ansible webservers -a 'ls'
    ansible-playbook -l webservers playbook.yml

And you can also use them in set-theory compositions like:

    ansible-playbook -l webservers:\!web1

See:

    http://www.ansibleworks.com/docs/intro_patterns.html


BTW There is no need to make your inventory-script conditionally create groups. Just have your inventory-script create all possible groups you need all the time, and let ansible figure out what groups/hosts are needed simply by using them on the command-line or playbooks.

PS If you have lots of custom groups based around properties of hosts, you can make dynamic groups based on facts using the group_by module. This is quite powerful, however make sure the groups exist prior to using them (in all playbooks). You cannot use these dynamic groups on the command-line since they don't exist at that point (!).

--
-- dag wieers, [email protected], http://dag.wieers.com/
-- dagit linux solutions, [email protected], http://dagit.net/

[Any errors in spelling, tact or fact are transmission errors]

--
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.

Reply via email to