# For a localhost where should variables be placed in an Inventory?

**URL:** <https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554>\
**Category:** Get Help\
**Tags:** playbook, inventory\
**Created:** [May 7, 2024, 10:39am UTC](https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554 "2024-05-07T10:39:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShanDesai](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@ShanDesai](https://forum.ansible.com/u/ShanDesai)\
**Post date:** [May 7, 2024, 10:39am UTC](https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554/1 "2024-05-07T10:39:26Z")

</div>

## Scenario

I have a set of playbooks which are distinctly meant to be run throughout on the device itself (`localhost`).

The playbooks are minor adoptions of playbooks that are actually meant to execute the tasks on inventories, but in order to keep a few distinctions and not to explicitly mention `localhost` in an inventory as a host, I have them in my repo.

The general playbooks that are meant to be run on multiple devices rely on group variables explicitly mentioned in `inventory/group_vars` directory. The playbooks use this variables to perform tasks accordingly on remote machines.

If I still rely on an inventory based variables logic - where do I add these variables in the inventory for just the `localhost`?

I do currently face errors (Undefined variables) when running the localhost playbooks because it cannot pick any variables up (assuming localhost is not in any group). Hence I am a bit confused as to how to keep these playbooks compatible to the most of scenarios?

I am assuming the only group here that I might try out is `ungrouped` in the inventory file? but I am not sure if it will work for `localhost`.

---

<div class="post-metadata">

**Author:** ![jpmens](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jpmens/32/5543_2.png) [@jpmens](https://forum.ansible.com/u/jpmens)\
**Post date:** [May 7, 2024, 10:55am UTC](https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554/2 "2024-05-07T10:55:39Z")

</div>

Have you tried placing your variables in `host_vars/localhost`, either parallel to your inventory or parallel to your playbook?

---

<div class="post-metadata">

**Author:** ![ShanDesai](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@ShanDesai](https://forum.ansible.com/u/ShanDesai)\
**Post date:** [May 7, 2024, 11:19am UTC](https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554/3 "2024-05-07T11:19:32Z")

</div>

Ah! almost forgot you can also have `host_vars`. This should work.

---

<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:** [June 6, 2024, 11:20am UTC](https://forum.ansible.com/t/for-a-localhost-where-should-variables-be-placed-in-an-inventory/5554/4 "2024-06-06T11:20:10Z")

</div>

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