Ansible ignores it’s configuration file (ansible.cfg), what could be the reason

ansiblemac-osxvagrant

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": [
    "web"
  ],
  "app": [
    "app-1"
  ],
  "vagrant": [
    "web",
    "app-1"
  ],
  "_meta": {
    "hostvars": {
      "web": {
        "ansible_ssh_host": "127.0.0.1",
        "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": "127.0.0.1",
        "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
[defaults]
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
[web]
[app]

[role_web:children]
web

[role_app:children]
app

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 >>
app-1

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

Best Answer

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

inventory

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