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

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.

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

1 Like

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

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