error with homebrew and ansible

2015-11-24

quick summary: Did you use homebrew to install ansible? Put your host file in /usr/local/etc/ansible/hosts

I’ve started playing around with ansible, and thought i’d use homebrew to install in on my mac.

First issue I had was running ansible all -m ping:

ERROR: Unable to find an inventory file, specify one with -i ?

So I created /etc/ansible/hosts and put the following in there:

[targets]
localhost   ansible_connection=local

And try ansible all -m ping again. Same error. Damn. it would work when I specified the host file using the -i flag, but I don’t want to do that all the time.

The man page assured me that /etc/ansible was the correct place:

-i PATH, --inventory=PATH
The PATH to the inventory hosts file, which defaults to /etc/ansible/hosts.

A bit of googling reminded me that all homebrew stuff lived under /usr/local, so a simple:

mkdir /usr/local/etc/ansible
vi /usr/local/etc/ansible/hosts

And adding these lines to the file:

[targets]
localhost   ansible_connection=local

And trying the ansible all -m ping command again resulted in success:

localhost | success >> {
    "changed": false,
    "ping": "pong"
}

Hooray, first issue easily overcome.