Could not find default inventory in Mac

I installed ansible(1.8.4) with homebrew in Mac OSX Yosemite.

I followed ansible doc and create ‘hosts’ file under /etc/ansible, and try with the most simple ansible command:

ansible my_inventory -m ping

and I got an error:

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

Then I figured that the default inventory path became:

/usr/local/etc/ansible/hosts

And It works if I created a hosts file in this folder.

I am curious if this is behaviour is something related to the convention for homebrew? If so, should we change ansible documentation?

Also, I found that even I created ansible.cfg in my current folder and change default inventory like this

[defaults]
inventory = $HOME/projects/ansible_playbooks/hosts

I will still get the same error if I don’t have any inventory file in:

/usr/local/etc/ansible/hosts

How can I overwrite the defaults in the current directory?

Thanks

Leo Liang

It is a convention of homebrew to install everything in /usr/local, to the point where they patch the source of applications to change paths.

I would not consider this something that should be updated in the ansible docs. Ideally, I would discourage anyone from installing ansible via homebrew, as it does some other nasty things that make it hard to extend and use.

Also within [defaults] the key has historically been called ‘hostfile’. As of the unreleased ansible 1.9, ‘hostfile’ is deprecated and the new option is ‘inventory’.

Hi Matt,

Thanks for your quick reply.

I actually found the instruction in ansible docs to install “Latest Releases Via Homebrew (Mac OSX)”, if install ansible is discourage, do you think it is possible to have a warning in the installation page?

I am actually aware that ansible is going to deprecated ‘hostfile’ and that is why in my ansible.cfg, I used ‘inventory’ not ‘hostfile’. I guess option ‘inventory’ is not working prior 1.9?

Thanks again for your reply.

Leo Liang

在 2015年3月17日星期二 UTC+11上午1:55:10,Matt Martz写道:

BTW, if Homebrew is not the best way to intsall Ansible in Mac OSX, then what is the best way you suggest to install Ansible in Mac OSX?

Cheers

Leo Liang

在 2015年3月17日星期二 UTC+11上午10:12:07,Jialiang Liang写道:

Hi,

With ansible being so “simple” I’d suggest this order of installation:

  • virtualenv with pip install
  • virtualenv with git checkout

With the current development speed and given that is indeed rather easy to run from git I’d think that anything else is just a major PITA. I’ve never even attempted to to anything but virtualenv and one of the above.

For “production” setups i usually use virtualenv+pip as I can nicely freeze the requirements, create a bootstrap script and send it around to colleagues which will then get exactly the versions that work.

(of course just my idea of how to actually use ansible)

/Martin