ansible.cfg relative paths

This needs some discussion not in tracker
https://github.com/ansible/ansible/issues/5185

When you create ansible.cfg with the following content:

[defaults]
hostfile = ./hosts

What kind of lookup will be more useful?

  1. From current directory you’re in?
  2. From directory of ansible.cfg?

Should your inventory file be changing every time you can just specify it with -i.

Inventory file is not changing.

Hi Michael,

Huge fan, long time listener, first time caller blah blah

My use case requires a relative path in a local ansible.cfg - I want to include it with my checkout (which could be put anywhere) and I’d really rather not have to -i or tell others to.

In my case, it seems my config file is actually ignored. I’ve set relative and absolute paths for hostfile, verified I’m using [defaults] and not [default], unset ANSIBLE_HOSTS (which I have set for global use) but it never seems to be observed. I’d really like to see -vvvv echo the hostfile and inventory file Ansible is using (so I could easily verify) but I can tell my hosts are not being used regardless.

Is there any known issue with local config files? I’m on an OSX machine, Ansible 1.4.2 installed via homebrew (please don’t say this is the problem, I love homebrew)

Cheers,

  • Steve

Here’s the code that describes the behavior:


def load_config_file():

    p = ConfigParser.ConfigParser()

    path1 = os.getcwd() + "/ansible.cfg"

    path2 = os.path.expanduser(os.environ.get('ANSIBLE_CONFIG', "~/.ansible.cfg"))

    path3 = "/etc/ansible/ansible.cfg"

    if os.path.exists(path1):

        p.read(path1)

    elif os.path.exists(path2):

        p.read(path2)

    elif os.path.exists(path3):

        p.read(path3)

    else:
        return None

    return p