Inventory variable not available in hostvars

22 views
Skip to first unread message

Douglas Hammond

unread,
Aug 24, 2016, 7:18:24 PM8/24/16
to Ansible Project
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?


Kai Stian Olstad

unread,
Aug 26, 2016, 2:39:30 PM8/26/16
to ansible...@googlegroups.com
On 24. aug. 2016 23:25, Douglas Hammond wrote:
> 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


> 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?

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

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages