'Ansible: path to ansible.cfg

I have this known issue. So I try to fix it but I don't see where I have to create my ansible.cfg (or does it already exist)? I tried it in my homedirectory but it still did not work.

sudo vi ~/.ansible.cfg

I read a lot about /etc/ansible but on my system it isn't there. I'm on Mac El Capitan. I've installed ansible by using pip.

ansible --version
ansible 1.9.4
  configured module search path = None


Solution 1:[1]

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

Solution 2:[2]

I got the same thing when I used pip. But I think better way is either using apt or yum according to your OS. I have centOS so following worked for me.

To get Ansible for CentOS 7, first ensure that the CentOS 7 EPEL repository is installed:

sudo yum install epel-release

Once the repository is installed, install Ansible with yum:

sudo yum install ansible

We now have all of the software required to administer our servers through Ansible.

Reference: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-centos-7

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MD5
Solution 2 RAJAT RAWAT