# \--extra-vars needs to go

**URL:** <https://forum.ansible.com/t/extra-vars-needs-to-go/11415>\
**Category:** Ansible Project\
**Created:** [April 17, 2012, 2:55am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415 "2012-04-17T02:55:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 17, 2012, 2:55am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/1 "2012-04-17T02:55:22Z")

</div>

Now that (on the integration branch) we can represent variables on a per host basis (among other things), --extra-vars as a CLI option is overcomplicating things.

In case where I don’t remember how things work, code dies. Thus --extra-vars needs to go.

If you want to pass variables into a playbook, define them in the vars file or the playbook, or use vars\_prompt to ask for them.

For instance if doing a release script, putting the release variable at the top of the playbook should be fine.

–Michael

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [April 17, 2012, 2:57am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/2 "2012-04-17T02:57:27Z")

</div>

--extra-vars was originally intended (on my part) as a way to pass  
vars to the inventory script -- so losing it will be a big problem for  
me, unless the inventory script has access to all the vars.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 17, 2012, 3:00am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/3 "2012-04-17T03:00:00Z")

</div>

What’s the full explanation of the use case?

i.e. what does the playbook do and what are the actual args you are passing to the inventory script  
and what is the logic of the inventory script?

vars _can_ come from both the playbook and the inventory at the same time (these are merged) so I don’t yet  
understand what this would be needed for.

Or to put it differently, there’s perhaps a better way to solve this?

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [April 17, 2012, 3:01am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/4 "2012-04-17T03:01:36Z")

</div>

I use extra-vars to pass a) a cobbler host and b) some filtering  
criteria to the inventory script.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 17, 2012, 3:03am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/5 "2012-04-17T03:03:00Z")

</div>

I would think you could just hard code the cobbler host in the script or make a configuration file for the inventory script in this case.

You may have to elaborate more on filtering criteria.

–Michael

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [April 17, 2012, 3:08am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/6 "2012-04-17T03:08:41Z")

</div>

I have a shell script that I execute like so:

play -H host1,host2 -L datacenter1 -s web,db ...and some other  
uninteresting arguments.

This tells inventory to only return data for those hosts, locations,  
and services. Some of this could be solved in other ways, but I'm not  
sure it all could.

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [April 17, 2012, 3:09am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/7 "2012-04-17T03:09:13Z")

</div>

(The shell script invokes ansible-playboook with the data packed into  
--extra-vars)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 17, 2012, 3:16am UTC](https://forum.ansible.com/t/extra-vars-needs-to-go/11415/8 "2012-04-17T03:16:53Z")

</div>

Ok, so…

To me, that sounds like you should be probably be defining and using groups, if web and db are what I think they are.  
“web” “datacenter” and so forth, look like groups.

However, there’s an easy fix. Teach your external inventory script to pay attention to environment variables, and then you can set anything you want. Have your playbook wrapper script set the variable, and then have the external inventory script read it.

–Michael
