# ansible.cfg relative paths

**URL:** <https://forum.ansible.com/t/ansible-cfg-relative-paths/14085>\
**Category:** Ansible Project\
**Created:** [December 6, 2013, 7:13am UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085 "2013-12-06T07:13:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [December 6, 2013, 7:13am UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085/1 "2013-12-06T07:13:59Z")

</div>

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

When you create ansible.cfg with the following content:

```auto
[defaults]
hostfile = ./hosts

```

What kind of lookup will be more useful?

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 6, 2013, 12:51pm UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085/2 "2013-12-06T12:51:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anatoly\_techtonik](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anatoly\_techtonik](https://forum.ansible.com/u/anatoly_techtonik)\
**Post date:** [December 6, 2013, 3:19pm UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085/3 "2013-12-06T15:19:32Z")

</div>

Inventory file is not changing.

---

<div class="post-metadata">

**Author:** ![Steve\_Pereira](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@Steve\_Pereira](https://forum.ansible.com/u/Steve_Pereira)\
**Post date:** [January 20, 2014, 9:44pm UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085/4 "2014-01-20T21:44:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 21, 2014, 12:48am UTC](https://forum.ansible.com/t/ansible-cfg-relative-paths/14085/5 "2014-01-21T00:48:42Z")

</div>

Here’s the code that describes the behavior:

```auto

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

```
