# extra-vars behavior

**URL:** <https://forum.ansible.com/t/extra-vars-behavior/20735>\
**Category:** Ansible Project\
**Created:** [March 1, 2016, 9:30pm UTC](https://forum.ansible.com/t/extra-vars-behavior/20735 "2016-03-01T21:30:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arthur\_Reyes](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Arthur\_Reyes](https://forum.ansible.com/u/Arthur_Reyes)\
**Post date:** [March 1, 2016, 9:30pm UTC](https://forum.ansible.com/t/extra-vars-behavior/20735/1 "2016-03-01T21:30:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [March 1, 2016, 9:50pm UTC](https://forum.ansible.com/t/extra-vars-behavior/20735/2 "2016-03-01T21:50:37Z")

</div>

I’ve used multiple vars similar to your second example for quite a while, and it’s [documented to be used like that](http://docs.ansible.com/ansible/playbooks_variables.html#passing-variables-on-the-command-line), 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

---

<div class="post-metadata">

**Author:** ![Arthur\_Reyes](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Arthur\_Reyes](https://forum.ansible.com/u/Arthur_Reyes)\
**Post date:** [March 1, 2016, 10:01pm UTC](https://forum.ansible.com/t/extra-vars-behavior/20735/3 "2016-03-01T22:01:17Z")

</div>

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=)
