2

I installed ansible using pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo pip install ansible

But I cannot find either ~/.ansible.cfg or etc/ansible in macOS.

$ansible --version

WARNING: Executing a script that is loading libcrypto in an unsafe way. This will fail in a future version of macOS. Set the LIBRESSL_REDIRECT_STUB_ABORT=1 in the environment to force this into an error.
ansible 2.10.0.dev0
  config file = None
  configured module search path = [u'/Users/nethminiromina/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/nethminiromina/Library/Python/2.7/lib/python/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.16 (default, Oct 17 2019, 17:14:30) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s

How can I find or setup inventory file?

2 Answers2

3

You can use ansible-config to show the config file location

% ansible-config --version
ansible-config [core 2.13.1]
  config file = None
  configured module search path = ['/Users/myusername/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/myusername/.ansible/collections:/usr/share/ansible/collections
  executable location = /Library/Frameworks/Python.framework/Versions/3.9/bin/ansible-config
  python version = 3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:39:15) [Clang 6.0 (clang-600.0.57)]
  jinja version = 3.1.2
  libyaml = True

In this case I had no configuration file (config file = None) so I generated an empty one (option --disabled means all entries are commented out) in the current directory with

% ansible-config init --disabled > ansible.cfg

Now ansible-config can find a configuration file in the current directory /localDir

% ansible-config --version                    
ansible-config [core 2.13.1]
config file = /localDir/ansible.cfg
[ . . . ]

Note: consider security issues Avoiding security risks with ansible.cfg in the current directory.

Here's the priority list of places where Ansible will search for a config file (see configuration file):

  • ANSIBLE_CONFIG (environment variable if set)
  • ansible.cfg (in the current directory)
  • ~/.ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg
user2314737
  • 27,088
  • 20
  • 102
  • 114
2

Q: "Cannot find etc/ansible"

A: pip show -f ansible should show the installed files. If the configuration file is missing create one. See Configuring Ansible.

Q: "How can I find or setup inventory file?"

A: See Where to store Ansible host file on Mac OS X.

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63