# \`--no-vars\` option for \`ansible-inventory(1)\`?

**URL:** <https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890>\
**Category:** Project Discussions\
**Tags:** inventory\
**Created:** [June 5, 2026, 10:26pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890 "2026-06-05T22:26:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirabilos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mirabilos/32/9721_2.png) [@mirabilos](https://forum.ansible.com/u/mirabilos)\
**Post date:** [June 5, 2026, 10:26pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/1 "2026-06-05T22:26:38Z")

</div>

Hi!

I’m using `ansible-inventory --list` to get a parsed view of the inventory¹.

Unfortunately, it does too much: it also outputs a huge (8 MB compared to maybe a dozen KB for the inventory) key called `_meta` which I have to immediately throw away again because I’m not interested.

I looked into whether I could use the Python3 API directly, but the docs say it’s internal and paws away.

So, this would not be a problem (I can just throw away that subkey)… except, to output that part, it needs the vault password.

I didn’t even notice because I have a thing that decrypts the vault password using `ssh-agent` automatically when needed (blogpost (in English) on that coming), but others have not yet set that up and did notice, so I added `--ask-vault-pass` for now.

Could please an option like `--no-vars` or `--no-meta` be added to the `ansible-inventory(1)` tool so that it just… doesn’t do that?

Having looked at the source, that would be an addition of… maybe three lines or so (plus indenting change).

* * *

① This is for a verification tool that checks things like, every host has exactly one host playbook xor one group playbook; every host playbook handles exactly one host; every host is in the inventory; every group playbook handles exactly one group; warn if hosts in the inventory have neither host nor group playbook; check host and group names against an RE; generate a “master playbook” that imports all others; etc. — it’s probably very specific to one certain (possibly suboptimal but historically grown) repo layout, but if there is interest, I could probably share it, I’d have to ask but experience tells me chances are good.

---

<div class="post-metadata">

**Author:** ![mirabilos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mirabilos/32/9721_2.png) [@mirabilos](https://forum.ansible.com/u/mirabilos)\
**Post date:** [June 5, 2026, 10:28pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/2 "2026-06-05T22:28:32Z")

</div>

(on that matter, it would be nice if the format was actually documented in the manpage and documented as stable, and if other tools outputting similar informations, like `ansible-playbook --list-hosts`, also had stable, documented, **script-parseable** output, at least with an option like `--batch` or so, no need to change the existing output if such an option is not given)

---

<div class="post-metadata">

**Author:** ![U880D](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/u880d/32/10032_2.png) [@U880D](https://forum.ansible.com/u/U880D)\
**Post date:** [June 8, 2026, 9:00am UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/3 "2026-06-08T09:00:47Z")

</div>

> [@mirabilos](#):
>
> Could please an option like `--no-vars` or `--no-meta` be added to the `ansible-inventory(1)` tool so that it just… doesn’t do that?

How about following the basics of Unix philosophy, using one tool for one task, resulting into

```auto
ansible-inventory --inventory hosts.ini --list | jq 'del(._meta)'

```

and an example output of

```json
{
  "all": {
    "children": [
      "ungrouped",
      "webservers"
    ]
  },
  "webservers": {
    "hosts": [
      "dev"
    ]
  }
}

```

It is also possible to remove the [Default groups](https://docs.ansible.com/projects/ansible/latest/inventory_guide/intro_inventory.html#default-groups) from the output by using

```auto
| jq 'del(._meta, .all)'

```

Would that be a feasible approach for you?

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [June 8, 2026, 12:00pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/4 "2026-06-08T12:00:18Z")

</div>

Have you considered using `ansible-inventory --graph` instead of `--list`? It does not show variables by default.

> (on that matter, it would be nice if the format was actually documented in the manpage and documented as stable, …

The `--list` output is stable, it’s the [same format](https://docs.ansible.com/projects/ansible/latest/cli/ansible-inventory.html#cmdoption-ansible-inventory-list) emitted by [inventory scripts](https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/script_inventory.html).

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [June 8, 2026, 5:55pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/5 "2026-06-08T17:55:05Z")

</div>

Another option is to create a Jinja2 template that dumps exactly the structure you want and run it from `ansible` or `ansible-playbook` via the `template` action.

---

<div class="post-metadata">

**Author:** ![mirabilos](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mirabilos/32/9721_2.png) [@mirabilos](https://forum.ansible.com/u/mirabilos)\
**Post date:** [June 8, 2026, 6:53pm UTC](https://forum.ansible.com/t/no-vars-option-for-ansible-inventory-1/45890/6 "2026-06-08T18:53:51Z")

</div>

> [@U880D](#):
>
> `ansible-inventory --inventory hosts.ini --list | jq 'del(._meta)'`

That’s what I’m doing now, as you can see from the first post, and that’s what _causes_ the problems because it accesses the vault.

> [@shertel](#):
>
> Have you considered using `ansible-inventory --graph` instead of `--list`?

Yes. It is the very counter-example of parsable, though. Good for a human quick overview (though what is `@ungrouped`?).

> [@bcoca](#):
>
> Another option is to create a Jinja2 template that dumps exactly the structure you want and run it from `ansible` or `ansible-playbook` via the `template` action.

Hmh, the `--list` output minus `_meta` is pretty much exactly what I want… and it goes to stdout instead of needing tempfiles…
