23

I’m on Mac OS X and new to Ansible. I forget how I installed it. I think via pip:

$ pip freeze
altgraph==0.12
ansible==1.9.2

At any rate, from what I'm reading there should be a config file in /etc/ansible/, but the content of that directory is just:

$ ls -a /etc/ansible/
.       ..      .hosts.swp  hosts       roles

It doesn’t look like there’s an environment variable defined either:

$ echo $ANSIBLE_CONFIG
# blank line

Ansible works as far as I can tell (without a local ansible.cfg, and there’s nothing in the ansible folder in the user dir), but I’m confounded.

Can someone please explain what I’m not getting here?

4 Answers 4

19

From what I know the Ansible config file (ansible.cfg) might be located here for user-level configuration settings:

~/.ansible.cfg

As well as the system-wide config located here; where you state you can’t find any such file:

 /etc/ansible/ansible.cfg

If somehow you have multiple users on your system, perhaps there is a ~/.ansible.cfg floating in one of their user directories you have forgotten about?

You state you might have installed it using pip, but checking the Homebrew formula for Ansible, it was only recently bumped from version 1.9.2 to 1.9.3 on September 4th. So perhaps you installed it via Homebrew?

And your main concern seems to be whether the ansible.cfg is necessary:

Ansible works as far as I can tell (without a local ansible.cfg, and there’s nothing in the ansible folder in the user dir), but I’m confounded.

Can someone please explain what I’m not getting here?

Yes, it should work fine without a configuration. For most pieces of software all a config file does is override the core system defaults. So if ansible.cfg is missing, Ansible would still work but only be using the core system defaults. As explained in Ansible’s official documentation:

Certain settings in Ansible are adjustable via a configuration file. The stock configuration should be sufficient for most users, but there may be reasons you would want to change them.

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
5
  • not in either place. and i'm the only user. i guess i could just copy it from the git repo and place it in one of those directories.
    – MikeiLL
    Sep 19, 2015 at 17:29
  • Good call. It wasn't installed via homebrew, but it was version 1.9.2. reinstalling via pip at the moment...
    – MikeiLL
    Sep 19, 2015 at 17:36
  • now at 1.9.3 but still can't find a config directory in either of the above locations. There's ~/.ansible/cp, and /etc/ansible/ with same contents.
    – MikeiLL
    Sep 19, 2015 at 17:40
  • Thanks. Makes sense. I just wasn't sure if stock configuration was normally stored in one of the referenced ansible.cfg files.
    – MikeiLL
    Sep 19, 2015 at 17:42
  • Me too : ) Now back to the ansible docs...
    – MikeiLL
    Sep 19, 2015 at 17:48
17

The homebrew formula replaces the string /etc/ansible in constants.py with /usr/local/etc/ansible. Seems like bad juju to me.

I did not have /usr/local/etc/ansible after brew install ansible. However, I did confirm that if you put a valid ansible.cfg there, it will be honored (for now).

My recommendations:

  1. Don't use brew to install Ansible.
  2. Be explicit about your config don't depend upon system environment globals, such as /etc/ansible/ansible.cfg.

Code Refs:

brew ansible formula replacement #475: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/ansible.rb#L475

ansible constants.py #61: https://github.com/ansible/ansible/blob/v1.9.3-1/lib/ansible/constants.py#L61

1
  • 3
    homebrew work in user space so everythings is under /usr/local. This is fine.
    – gagarine
    Aug 31, 2016 at 19:35
5

On OSX, I had installed ansible using pip and found that ansible.cfg is not present in /etc/ansible or in my home directory.

Source: https://github.com/ansible/ansible/issues/18512

pip doesn't generally install configuration files and pip with ansible is no different. If you just want to try out ansible, it generally works without an ansible.cfg file. (You do need to specify some inventory but you can do that on the command line rather than a file if you want). If you want to get a sample config file to adapt, you can get it from the tarball or the source repository here: https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg

Inventory files are explained here: http://docs.ansible.com/ansible/intro_inventory.html To specify hosts for inventory on the command line instead just do something like this:

ansible -i 'host1,host2,host3'  all -m command -a 'hostname'

If you want to specify a single host via the command line use a trailing comma in the inventory string:

ansible -i 'host1,' all -m command -a 'hostname'
4

I've found that Homebrew will not create a /etc/ansible directory, nor will it create a config or host file. However if you create the /etc/ansible directory and copy the config from the github repository into the /etc/ansible directory it will recognize that as a config.

You may also want to go into that config and uncomment the line which specifies the inventory location as well to:

inventory = /etc/ansible/hosts

Upon doing this, ansible will perform the same way with a homebrew install as it does from any other install and the documentation you find online can be utilized with the homebrew version.

1
  • 1
    /usr/local/etc/ was not recognized. Tried creating the /etc/ansible/ directory and moved hosts and ansible.cfg worked fine!
    – aelkz
    Feb 21, 2019 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .