Ansible: path to ansible.cfg

From the docs:

Changes can be made and used in a configuration file which will be processed in the following order:

  • ANSIBLE_CONFIG (an environment variable)
  • ansible.cfg (in the current directory)
  • .ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg

I'm not sure this does 100% apply to 1.9.4. Ansible is terrible in versioning their documentation. (=there only is one version and not always the version a feature was introduced or changed is mentioned)

But I am sure everything except ~/.ansible.cfg works in 1.x as I have tried that before.

So if you have created ~/.ansible.cfg and it is not being used, check if the environment var ANSIBLE_CONFIG is set or there is one file in the directory from where you call ansible. The first one found will be used. processed in the following order does not mean they will be merged in that order. First one found wins.

I read a lot about /etc/ansible but on my system it isn't there.

Yeah, that depends on how Ansible was installed. If it's not there you could just create it but if you do not need it, no need to create it. I actually deleted mine as I see no use for it.


For latest version (2.7.6) if you install via pip you wont get ansible folder in /etc. so this is what you get when you do ansible --version

ansible --version
ansible 2.7.6
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible

But once you manually create directory under /etc as ansible and add ansible.cfg file there ansible automatically detects it. but you will have to configure the rest manually like hosts file..etc . so after this we get

ansible --version
ansible 2.7.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible

Tags:

Ansible