# can extra-vars be a parameter from the host file ?

**URL:** <https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190>\
**Category:** Ansible Project\
**Created:** [April 18, 2016, 11:37am UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190 "2016-04-18T11:37:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [April 18, 2016, 11:37am UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190/1 "2016-04-18T11:37:27Z")

</div>

Hello,

I would like to set a lot of parameters when playing my playbook, depending on the server/user where it will be deployed so the idea is to set it in the hosts file.

It doesn’t seem to work as my varaibles are no set, here is what I plan to do:

[webserver]  
linuxserv ansible\_connection=local ansible\_user=aa12 extra-vars=“@/home/root/vars/vars.json”

running the playbook this way:

ansible-playbook deploy.yml

and with vars.json:

{  
“ENVT”: “aa12”,  
“MODULE”: “tomweb”,  
“RELEASE”: “1.2”,  
}

Is this possible or do I have to try to load the vars parameter file in the playbook ?

Regards

---

<div class="post-metadata">

**Author:** ![toshywoshy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/toshywoshy/32/7855_2.png) [@toshywoshy](https://forum.ansible.com/u/toshywoshy)\
**Post date:** [April 18, 2016, 12:50pm UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190/2 "2016-04-18T12:50:57Z")

</div>

If the variables are host specific as you first indicate, you can use host variables or group variables  
You need to have the specific directory structure :  
- hosts (file)  
- host\_vars/ (directory)  
- group\_vars/ (directory)

$ cat hosts  
[webserver]  
linuxserv

$ cat host\_vars/linuxserv

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 18, 2016, 11:22pm UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190/3 "2016-04-18T23:22:21Z")

</div>

extra\_vars= inside your hosts file has no meaning, it just gives a path to a variable named ‘extra\_vars’.

Ansible can consume the JSON directly, if you don’t want to copy it you can symlink it to host\_vars/hostname or group\_vars/group\_name and Ansible will assign those appropriately.

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [April 19, 2016, 7:49am UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190/4 "2016-04-19T07:49:13Z")

</div>

THank you, my issue is the following: **the variables are host/user specific** , so I am trying to find a way to set them in an easy way as t **hey will pilote the playbook execution**. (if the parameter is tomcat then the tomcat role will be played etc …)  
So using a group\_var is not easy to manage, I was thinking about setting vars in the hosts in a tab, this way:  
[linuxserver]  
server1 ansible\_user=aa01 vartab=“1;tomcat;release1”

and then in the playbook getting the variables using the vartab[1] …  
I am new in ansible, I don’t know if this is possible.

Thanks for your help  
Regards

---

<div class="post-metadata">

**Author:** ![fanvalt](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@fanvalt](https://forum.ansible.com/u/fanvalt)\
**Post date:** [April 19, 2016, 10:31am UTC](https://forum.ansible.com/t/can-extra-vars-be-a-parameter-from-the-host-file/21190/5 "2016-04-19T10:31:20Z")

</div>

Hello,

I did solve my issue by using an array to pass my parameters in the hosts file:

[deployserver]  
linuxserv1 ansible\_connection=local ansible\_user=aa01 PARAM=“[‘/aa01/dev’, ‘tomweb’, ‘1.2’]”

linuxserv1 ansible\_connection=local ansible\_user=bb01 PARAM=“[‘/bb01/dev’, ‘query’, ‘15.1’]”

linuxserv2 ansible\_connection=local ansible\_user=aa01 PARAM=“[‘/aa01/prd’, ‘tcserver’, ‘1.2’]”

and in my playbook:

envt: “{{ PARAM[0]|default (‘fvfv’) }}”  
module: “{{ PARAM[1]|default (‘tomcat’) }}”

…

Thank you,  
Regards
