# Extra-vars flag with file not populating variables with ansible-inventory command

**URL:** <https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963>\
**Category:** Get Help\
**Tags:** netbox\
**Created:** [November 17, 2024, 3:36pm UTC](https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963 "2024-11-17T15:36:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jforman](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@jforman](https://forum.ansible.com/u/jforman)\
**Post date:** [November 17, 2024, 3:36pm UTC](https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963/1 "2024-11-17T15:36:23Z")

</div>

I’m trying to integrate my [netbox](https://netboxlabs.com/docs/netbox/en/stable/) installation with ansible to use it as an inventory source of truth.

I’m merely trying to do the first type of integration which is to list the hosts in netbox.

My command

```auto
% ansible-inventory --list -i netbox_inv.yaml --extra-vars "@netbox_vars.yaml" -vvvv

```

netbox\_inv.yaml:

```auto
---
plugin: netbox.netbox.nb_inventory
validate_certs: true
api_endpoint: "{{ api }}"
token: "{{ token }}"
config_context: false
group_by:
  - device_roles 

```

netbox\_vars.yaml:

```auto
---
api: "https://mynetbox.local.lan"
token: "longlonglongtoken"

```

But when I run my command, the output looks like this:

```auto
ansible-inventory [core 2.17.6]
  config file = None
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.11.1 (main, Dec 21 2022, 08:24:23) [GCC 10.2.1 20210110] (/usr/local/bin/python)
  jinja version = 3.1.4
  libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /home/ansible/netbox_inv.yaml as it did not pass its verify_file() method
script declined parsing /home/ansible/netbox_inv.yaml as it did not pass its verify_file() method
Loading collection netbox.netbox from /usr/local/lib/python3.11/site-packages/ansible_collections/netbox/netbox
Using inventory plugin 'ansible_collections.netbox.netbox.plugins.inventory.nb_inventory' to process inventory source '/home/ansible/netbox_inv.yaml'
Fetching: {{ api }}/api/status
toml declined parsing /home/ansible/netbox_inv.yaml as it did not pass its verify_file() method

```

Note the “{{api}}” variable that is NOT substituted when trying to fetch from the API URL. When I put the actual URL and token values into the `netbox_inv.yaml`, things work.

Am I using the `extra-vars` flag incorrectly, or perhaps written the yaml wrong? Any help greatly appreciated

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [November 17, 2024, 5:52pm UTC](https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963/2 "2024-11-17T17:52:28Z")

</div>

While this may change in the future, right now variables do not automatically work in inventory configs and plugin authors have to manually template things if they need to allow users to use variables. Looking at this plugin, it appears that the only thing that it templates is the `token`, so you cannot use a Jinja expression in `api_endpoint`.

---

<div class="post-metadata">

**Author:** ![jforman](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@jforman](https://forum.ansible.com/u/jforman)\
**Post date:** [November 17, 2024, 9:24pm UTC](https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963/3 "2024-11-17T21:24:18Z")

</div>

Wow, youre right. I can make `token` a variable, but not api\_endpoint. While unfortunate, it’s a bit more secure than having neither of them. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 17, 2024, 9:24pm UTC](https://forum.ansible.com/t/extra-vars-flag-with-file-not-populating-variables-with-ansible-inventory-command/10963/4 "2024-12-17T21:24:20Z")

</div>

Closed on December 17, 2024, 9:24pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
