According to http://docs.ansible.com/ansible/intro_installation.html
Once running the env-setup script you’ll be running from checkout and the default inventory file will be /etc/ansible/hosts.
Do I need to create an /etc/ansible/hosts
file?
And right below this there's a warning:
Note
ANSIBLE_INVENTORY is available starting at 1.9 and substitutes the deprecated > ANSIBLE_HOSTS
So, am I supposed to be using an alternative to the hosts file?
Best Answer
Technically speaking this file, in this path, is not required for Ansible to run.
The inventory file, as it is called, is required, but it can be placed elsewhere on the filesystem and is path referenced in the command line (
-i
), inansible.cfg
file (either in your home or current directory), or environment variable (ANSIBLE_INVENTORY
).Ansible coming from Homebrew on OS X places the file in
/usr/local/etc/ansible
to allow regular user to modify the files without giving the account write permissions under the/etc
branch.You might even use an undocumented trick which allows Ansible to be run against an ad-hoc created list of servers.
This notice means the name of the environment variable pointing to the inventory file. It is not "an alternative to the hosts file", it is an alternative to the ANSIBLE_HOSTS variable.
There is a comment in the source indicating the reason for change was confusing naming.
Ansible community started to refer to the file containing host and group definitions as "hosts file", but as it has different structure to the system hosts fleet, a new name "inventory" was implemented. Still some references (like the default filename) exist.