Playbook look for hosts file

Hi,

It seems common practice for playbooks to have a “hosts” file in the root of the playbook.
When you run a playbook you have to supply it via the -i parameter, otherwise you will get the error: “ERROR: Unable to find an inventory file, specify one with -i ?”

It would be nice if Ansible would automaticly detect the hosts file in the playbook folder. Less arguments would make it even easier to use.

I think explicitly passing in the inventory is OK: pretty soon you’ll have at least two of them (staging/prod etc.), and you REALLY don’t want to apply changes to the wrong set of hosts :wink:

If you still want to set a default inventory path, you can do this through ANSIBLE_HOSTS environment variable or by setting “hostfile” in ansible.cfg

Yvo van Beek yvo@codegazer.com napisał:

For staging you create a separate group in the same hostfile right?
And you can’t name them both “hosts” :), so that shouldn’t be a problem.

I’m using separate inventory for staging, to be extra sure those environments don’t mix. And it’s actually a pretty standard practice to do so.