# including host\_vars in with\_items using roles

**URL:** <https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613>\
**Category:** Ansible Project\
**Created:** [October 4, 2013, 10:30pm UTC](https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613 "2013-10-04T22:30:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.ibarra](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@michael.ibarra](https://forum.ansible.com/u/michael.ibarra)\
**Post date:** [October 4, 2013, 10:30pm UTC](https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613/1 "2013-10-04T22:30:27Z")

</div>

Hi all,

I’m trying to use one role for two different hosts, each one using different playbooks.  
The behaviour I’m expecting is if I have n-deploy-web hosts they should get trackX.war copied in /var/lib/tomcat6/webapps, but if it’s n-deploy-dcs hosts they should get mdrcX.war,mdlsX.war,ctracfreeX.war

At first, running the playbook I get sintax error due to the braces… but removing them I get /path/to/deploy\_files.war doesn’t exists.

If there’s a way to get this running… link to the docs, examples or whatever that could help me… I will appreciate it.

$cat hosts  
[deploy-web]  
192.168.5.215

[deploy-web:vars]  
service=livetrack  
**service\_num=1**  
**deploy\_files=track**

[deploy-dcs]  
192.168.5.215

[deploy-dcs:vars]  
service=livetrack  
**service\_num=1**  
**deploy\_files=[mdrc,mdls,ctracfree]**

$cat deploy.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 10:46pm UTC](https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613/2 "2013-10-04T22:46:57Z")

</div>

Sure, this is a simple YAML gotcha.

If you have something that is like

foo: {{ bar }}

You have to quote it so YAML doesn’t think you mean a dictionary:

foo: “{{ bar }}”

Also don’t do $item, better to standardize on {{ item }} there too

---

<div class="post-metadata">

**Author:** ![michael.ibarra](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@michael.ibarra](https://forum.ansible.com/u/michael.ibarra)\
**Post date:** [October 4, 2013, 11:01pm UTC](https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613/3 "2013-10-04T23:01:50Z")

</div>

As I say in my native language… “Gracias”.

It worked for the deploy-web.yml playbook, but now I’m facing another issue, is this syntax correct?

**deploy\_files=[mdrc,mdls,ctracfree]**

The deploy-dcs.yml playbook fails saying path/to/file don’t exist.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 4, 2013, 11:36pm UTC](https://forum.ansible.com/t/including-host-vars-in-with-items-using-roles/13613/4 "2013-10-04T23:36:16Z")

</div>

You cannot define structured variables in your INI files (at least, not in 1.3)

Look into “group\_vars/groupname” files and “host\_vars/hostname” directories alongside your inventory file, and this is a great place to define structured data.
