ansible installation: no /etc/ansible/hosts file

No file for /etc/ansible/hosts

Where is this file? Instructor opened an automatically generated /etc/ansible/hosts file but there is no such file in Mac OSX after ansible is installed?

Am I supposed to create this file myself or it is automatically generated? as I cannot find it on Mac OSX after

$brew install ansible

as well as

$pip install ansible

Thanks

You have to create it by yourself as pip and brew didn’t create it. I think you even didn’t have /etc/ansible directory.

We don’t bother with the /etc/ansible/hosts file because we installed ansible in a different directory. So we always specify which host file to use in our run. I.e. when in the ansible directory I execute:

ansible-playbook -i <hosts_file> site.yml -vv

What if you want to use another directory for hosts, this is where the ansible.cfg file comes in handy. So where does this file go in MacOSX?

https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html#configuration-file

Referenced here in order at what ansible looks for…personally I never use /etc/ansible/ansible.cfg and tend to use a master one in ~/ or ansible.cfg per project directory which specifies other certain criteria I need for my playbook

https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings

  • ANSIBLE_CONFIG (environment variable if set)

  • ansible.cfg (in the current directory)

  • ~/.ansible.cfg (in the home directory)

  • /etc/ansible/ansible.cfg