# Implicit use of inventory script

**URL:** <https://forum.ansible.com/t/implicit-use-of-inventory-script/24580>\
**Category:** Ansible Project\
**Created:** [May 26, 2017, 2:52pm UTC](https://forum.ansible.com/t/implicit-use-of-inventory-script/24580 "2017-05-26T14:52:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivier2](https://avatars.discourse-cdn.com/v4/letter/o/ac91a4/32.png) [@olivier2](https://forum.ansible.com/u/olivier2)\
**Post date:** [May 26, 2017, 2:52pm UTC](https://forum.ansible.com/t/implicit-use-of-inventory-script/24580/1 "2017-05-26T14:52:50Z")

</div>

Hi,

I have been experiencing a rather peculiar issue when using an in-house dynamic inventory (output here: [https://gist.github.com/oboukili/4bfc95d97fc340e770321201f70dce4c](https://gist.github.com/oboukili/4bfc95d97fc340e770321201f70dce4c) ) in conjunction with static group\_vars files.  
When using this simple playbook:

```auto
---
- hosts: infrastructure
  become: true
  pre_tasks:
    - name: debug
      debug:
        msg: "{{ hostvars[item] }}"
      with_items: "{{ groups['infrastructure'] }}"
...

```

```auto
## Invocation:

ansible-playbook -i ~/Workspaces/ansible-inventory/mycloud includes/test.yml

## Output:

PLAY [infrastructure] ***********************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************
ok: [apps-public1]
ok: [bastion]

TASK [debug] ********************************************************************************************************************************************************************************************************
fatal: [apps-public1]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.hostvars.HostVars object' has no attribute u'apps-public1'\n\nThe error appears to have been in '/home/bki/Workspaces/playbooks/test.yml': line 5, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n pre_tasks:\n - name: debug\n ^ here\n"}
fatal: [bastion]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.hostvars.HostVars object' has no attribute u'apps-public1'\n\nThe error appears to have been in '/home/bki/Workspaces/playbooks/test.yml': line 5, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n pre_tasks:\n - name: debug\n ^ here\n"}

```

When I delete the group\_vars folder, everything runs fine (but I lose, of course all the static configuration).  
More specifically, I did a lot of debugging with the use of the inventory script and without, and I pinpointed the issue to the ansible.template.AnsibleJ2Vars. **get\_item** () getter (ansible/template.vars.py) that silently fails on this particular step when mixing dynamic inventory script and static group\_vars files:

variable = self.\_templar.\_available\_variables[varname]".

(its value would then not be a hostvars object instance, but a string:  
“Unable to get repr for \<class ‘ansible.vars.hostvars.HostVars’\>”)

Could anybody have pointers?

Thanks a lot,

–Olivier

---

<div class="post-metadata">

**Author:** ![olivier2](https://avatars.discourse-cdn.com/v4/letter/o/ac91a4/32.png) [@olivier2](https://forum.ansible.com/u/olivier2)\
**Post date:** [May 31, 2017, 2:11pm UTC](https://forum.ansible.com/t/implicit-use-of-inventory-script/24580/2 "2017-05-31T14:11:29Z")

</div>

Replying to myself as I have figured out the issue (but I still do not understand it though).

I had this hash in the group\_vars/infrastructure.yml file:

telegraf\_agent\_output: - type: influxdb config: - urls = [“{{ hostvars[groups[‘influxdb’][0]][‘influxdb\_url’] }}”] - database = “telegraf” - precision = “us” - retention\_policy = “” - timeout = “10s” - username = “telegraf” **- password = “{{ hostvars[groups[‘influxdb’]|random][‘influxdb\_secrets’][‘telegraf’] }}”** - user\_agent = “telegraf\_{{ inventory\_hostname }}”

Replacing the **|random** part by a list index fixed it:  
**- password = “{{ hostvars[groups[‘influxdb’][0][‘influxdb\_secrets’][‘telegraf’] }}”**

I’ll open an issue with a simple reproductible case later.

Cheers,
