# Calling "sub" variable in task

**URL:** <https://forum.ansible.com/t/calling-sub-variable-in-task/15267>\
**Category:** Ansible Project\
**Created:** [May 19, 2014, 10:34am UTC](https://forum.ansible.com/t/calling-sub-variable-in-task/15267 "2014-05-19T10:34:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Bozic](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Martin\_Bozic](https://forum.ansible.com/u/Martin_Bozic)\
**Post date:** [May 19, 2014, 10:34am UTC](https://forum.ansible.com/t/calling-sub-variable-in-task/15267/1 "2014-05-19T10:34:22Z")

</div>

Hi,

I'm trying to deploy Apache with virtualhosts and their aliases and directories. In order to do so I've setup vars host\_vars, Apache vhost config template and task file. With this setup I can create complete config per virtualhost, but I can't figure out how to call the var within task to create the directory.

host\_vars/myhost example with two virtualhosts:

---

<div class="post-metadata">

**Author:** ![Abhijit\_Menon-Sen2](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhijit\_Menon-Sen2](https://forum.ansible.com/u/Abhijit_Menon-Sen2)\
**Post date:** [May 19, 2014, 11:45am UTC](https://forum.ansible.com/t/calling-sub-variable-in-task/15267/2 "2014-05-19T11:45:12Z")

</div>

The reason this doesn't work is that your vhost\_dir is a list.

Perhaps you could use something like:

&nbsp;&nbsp;&nbsp;&nbsp;- name: create additional vhost dirs  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file: path={{ item.1 }} state=directory group=apache mode=0755  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: apache\_vhosts is defined  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_subelements:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- apache\_vhosts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- vhost\_dirs

[http://docs.ansible.com/playbooks\_loops.html#looping-over-subelements](http://docs.ansible.com/playbooks_loops.html#looping-over-subelements)

-- ams
