I'm running Vagrant 1.8.1 and ansible 1.8.4 on Mac OS.

I've started 2 Ubuntu machines on vagrant:

itais-MacBook-Pro:ansible-dir itaiganot$ ./dev/hosts --list | jq '.'
  "web": [
  "app": [
  "vagrant": [
  "_meta": {
    "hostvars": {
      "web": {
        "ansible_ssh_host": "",
        "ansible_ssh_port": "2201",
        "ansible_ssh_user": "vagrant",
        "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/web/virtualbox/private_key"
      "app-1": {
        "ansible_ssh_host": "",
        "ansible_ssh_port": "2202",
        "ansible_ssh_user": "vagrant",
        "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/app-1/virtualbox/private_key"

I have an ansible.cfg file in the current directory where the VagrantFile also resides.

itais-MacBook-Pro:ansible-dir itaiganot$ cat ansible.cfg
host_key_checking = False
inventory = dev

in the dev directory there are two files: hosts - which is a python script which automatically finds the IP of the booted vagrant machines and another file which includes the roles configurations:

itais-MacBook-Pro:dev itaiganot$ cat static



I'm trying to run the following command: ansible role_app -a 'hostname'

But i'm getting the following error:

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

I've googled it and found that I can export a variable to point to the config, like so:

export ANSIBLE_CONFIG=/Users/itaiganot/ansible-dir/ansible.cfg

But that didn't help me as well.

By the way, adding the dev directory as inventory to the command works:

itais-MacBook-Pro:ansible-dir itaiganot$ ansible role_app -a 'hostname' -i dev
app-1 | success | rc=0 >>

Any idea why the ansible.cfg file is ignored by ansible?

  • Have you tried using the absolute path for the inventory location? – Diamond Mar 30 '16 at 14:10
  • Yea just tried it but to no avail... – Itai Ganot Mar 30 '16 at 14:13

According to Ansible doc: http://docs.ansible.com/ansible/intro_configuration.html#inventory, this variable is not availabe before version 1.9:


This is the default location of the inventory file, script, or directory that Ansible will use to determine what hosts it has available to talk to:

inventory = /etc/ansible/hosts

It used to be called hostfile in Ansible before 1.9

Another thing would be to make sure that there is not another ansible.cfg file available in the system:http://docs.ansible.com/ansible/intro_configuration.html

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.