Can ansible dynamic inventory accept arguments ?

602 views
Skip to first unread message

Ritesh Shetty

unread,
May 14, 2015, 2:30:22 PM5/14/15
to ansible...@googlegroups.com
Hello !
I have read through some forum posts that i could use env variables but i really do not want to do so. So wanted to know if ansible dynamic inventory can accept a variable


Ritesh

Matt Martz

unread,
May 14, 2015, 2:44:08 PM5/14/15
to ansible...@googlegroups.com
Dynamic inventory scripts only accept 2 arguments that ansible will actively attempt to call:  --host and --list.

To provide additional configuration, your inventory script could have a config file, or utilize ENV vars as suggested in the other posts you have read.

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1c91803b-dade-471f-88e0-c0f9a1163030%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Bob Brown

unread,
May 15, 2015, 7:19:41 PM5/15/15
to ansible...@googlegroups.com
Not sure exactly what you mean by "accept arguments".

You can do something like add the varible into the play book

   hosts: ' {{ hosts }}'

and then when you run the playbook you can say something like

ansible-playbook -e "hosts=HOSTNAME" playbook.yml 
OR better yet, use the inventory generated tag names lik
ansible-playbook -e "hosts=tag_Name_cronbox-ops1-cronbox" playbook.yml

In "-e" you can add several value pairs that will act as variables.

Bob

Brian Coca

unread,
May 16, 2015, 11:29:08 AM5/16/15
to ansible...@googlegroups.com
don't use variables that overlap with keywords, use 'targets' instead
of 'hosts', for example
> https://groups.google.com/d/msgid/ansible-project/230076ba-36d2-4dd5-a815-3cb53f410f62%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages