# Inventory variable not available in hostvars

**URL:** <https://forum.ansible.com/t/inventory-variable-not-available-in-hostvars/22375>\
**Category:** Ansible Project\
**Created:** [August 24, 2016, 9:25pm UTC](https://forum.ansible.com/t/inventory-variable-not-available-in-hostvars/22375 "2016-08-24T21:25:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Hammond](https://avatars.discourse-cdn.com/v4/letter/d/5f8ce5/32.png) [@Douglas\_Hammond](https://forum.ansible.com/u/Douglas_Hammond)\
**Post date:** [August 24, 2016, 9:25pm UTC](https://forum.ansible.com/t/inventory-variable-not-available-in-hostvars/22375/1 "2016-08-24T21:25:26Z")

</div>

I’m trying to create client configs for each host in a group. When the template is parsed the inventory set variable is not available in the template.

bareos/Defaults/main.yml

bareos\_client\_fileset: SomeFileSet

bareos/tasks/main.yml

- name: Install director client configs  
template:  
src: client.conf.j2  
dest: /etc/bareos/bareos-dir.d/clients/{{ item }}.conf  
with\_items: “{{ groups[‘bareos\_clients’] }}”

bareos/templates/client.conf.js

{{ hostvars[item][‘bareos\_client\_fileset’] }}

How can I get the correct inventory variable from hostvars in this case?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 26, 2016, 6:39pm UTC](https://forum.ansible.com/t/inventory-variable-not-available-in-hostvars/22375/2 "2016-08-26T18:39:16Z")

</div>

> I'm trying to create client configs for each host in a group. When the  
> template is parsed the inventory set variable is not available in the  
> template.
> 
> bareos/Defaults/main.yml
> 
> bareos\_client\_fileset: SomeFileSet

This is not a inventory file syntax, maybe you are looking for group\_vars and/or host\_vars.

The directory structure Ansible understand is documented here  
[https://docs.ansible.com/ansible/playbooks\_best\_practices.html#directory-layout](https://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout)

> bareos/tasks/main.yml
> 
> - name: Install director client configs  
> &nbsp;&nbsp;template:  
> &nbsp;&nbsp;&nbsp;&nbsp;src: client.conf.j2  
> &nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/bareos/bareos-dir.d/clients/{{ item }}.conf  
> &nbsp;&nbsp;with\_items: "{{ groups['bareos\_clients'] }}"
> 
> bareos/templates/client.conf.js
> 
> {{ hostvars[item]['bareos\_client\_fileset'] }}
> 
> How can I get the correct inventory variable from hostvars in this case?

I recommend starting read here  
[https://docs.ansible.com/ansible/intro.html](https://docs.ansible.com/ansible/intro.html)  
it will give you a basic understanding of Ansible.
