extra-vars behavior

19 views
Skip to first unread message

Arthur Reyes

unread,
Mar 1, 2016, 4:33:30 PM3/1/16
to Ansible Project
I didn't see it listed in Issues, so I thought I would ask here if a recent discovery was actually a bug.

I'm working on some shell wrappers for the ansible-playbook and wanted to maintain a certain level of pedantry. It appears that ansible-playbook will except multiple --extra-vars options and append them to a single argv, which is what I expect from Python. 

In other words, this:

ansible-playbook site.yml --extra-vars "hosts='*CUS03*'" --extra-vars "foo=''" --extra-vars "bar='Yes'"


Is the same as this:


ansible-playbook site.yml --extra-vars "hosts='*CUS03*' foo='' bar='Yes'"


This is a good thing for me, but before I continue working on a wrapper that relies on this behavior, I figured I should ask around to see if this is actually an Issue.


Thank you,



Arthur

Joanna Delaporte

unread,
Mar 1, 2016, 4:50:38 PM3/1/16
to Ansible Project
I've used multiple vars similar to your second example for quite a while, and it's documented to be used like that, so I believe it is a feature, not a bug. I'm not sure I have ever used quotes inside the extra vars list, but I would guess you can use singles inside the doubles.

The following is how I have frequently used extra-vars:

ansible-playbook playbook.yml --extra-vars "hosts=hosts-group user=ansible-user var2=27" 


Joanna

Arthur Reyes

unread,
Mar 1, 2016, 5:01:17 PM3/1/16
to Ansible Project
I started reading the code and I agree it is a feature. I would recommend looking at this file to see how the playbook treats each option. Very informative:
ansible/lib/ansible/cli/__init__.py

        if runtask_opts:

            parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",

                help="set additional variables as key=value or YAML/JSON", default=[])

Reply all
Reply to author
Forward
0 new messages