How to pass command line arg as input for dynamic-inventory executable program during ansible-playbook launch

209 views
Skip to first unread message

Naren

unread,
Mar 19, 2016, 11:46:45 PM3/19/16
to Ansible Project
dynamic inventory can be achieved by

ansible-playbook -i dynamicInventory.py myplaybook.yml

in case I need to pass some dynamic input to the dynamicInventory.py program itself, how can I do that. Command line argument is not working when it coupled with ansible-playbook command

Any suggestions


Brian Coca

unread,
Mar 20, 2016, 12:05:03 AM3/20/16
to ansible...@googlegroups.com
there is no way to do what you ask, options for dynamic inventory are set either in configuration files or environment variables.


----------
Brian Coca

Dejay Clayton

unread,
Mar 20, 2016, 1:24:32 AM3/20/16
to Ansible Project
What operating system are you using to execute ansible-playbook?

Naren

unread,
Mar 20, 2016, 5:55:41 AM3/20/16
to Ansible Project
Ubuntu

Naren

unread,
Mar 20, 2016, 7:18:38 AM3/20/16
to Ansible Project
Environment variable kind of solution is good as long as I call my playbooks from console. But when it comes to automation by integrating with external systems; the inventory generator/builder should be good enough to pull inventory artifacts from database, REST APIs,...

All I need is something like

ansible-playbook -i dynamicInventory.py --script-args "location=chennai region=south" my_playbook.yml

here '--script-args' helps dyamicInventory.py program to pull inventory artifacts for specified location and region from some datastore

Benjamin Redling

unread,
Mar 20, 2016, 7:49:36 AM3/20/16
to ansible...@googlegroups.com
On 2016-03-20 12:18, Naren wrote:
> Environment variable kind of solution is good as long as I call my
> playbooks from console. But when it comes to automation by integrating with
> external systems; the inventory generator/builder should be good enough to
> pull inventory artifacts from database, REST APIs,...
>
> All I need is something like
>
> ansible-playbook -i dynamicInventory.py --script-args "location=chennai
> region=south" my_playbook.yml
>
> here '--script-args' helps dyamicInventory.py program to pull inventory
> artifacts for specified location and region from some datastore

What aspect of automation keeps you from setting environment variables?
Where is the difference between calling from console and calling from a
script?

E.g.,

SCRIPTARGS="location=chennai region=south" bash -c 'ansible-playbook -i
dynamicInventory.py my_playbook.yml'

When you evaluate SCRIPTARGS inside dynamicInventory.py I don't see
where the difference is compared to your "--script-args" -- apart from
the syntax.

Regards,
Benjamin
--
FSU Jena | JULIELab.de/Staff/Benjamin+Redling.html
vox: +49 3641 9 44323 | fax: +49 3641 9 44321
Reply all
Reply to author
Forward
0 new messages