Inventory variable not available in hostvars

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?

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.