# problems to address a configuration via ANSIBLE\_CONFIG

**URL:** <https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775>\
**Category:** Ansible Project\
**Created:** [September 22, 2021, 5:52pm UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775 "2021-09-22T17:52:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [September 22, 2021, 5:52pm UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/1 "2021-09-22T17:52:55Z")

</div>

hi everybody,

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 22, 2021, 6:39pm UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/2 "2021-09-22T18:39:46Z")

</div>

I just tried this out and apparently the path you specify for  
ANSIBLE\_CONFIG has to actually exist:

dick.visser@ams-049 ~ % export ANSIBLE\_CONFIG=/opt/nonexistent/ansible.cfg  
dick.visser@ams-049 ~ % ansible --version  
ansible 2.10.12  
&nbsp;&nbsp;config file = /Users/dick.visser/.ansible.cfg  
&nbsp;&nbsp;configured module search path =  
['/Users/dick.visser/.ansible/plugins/modules',  
'/usr/share/ansible/plugins/modules']  
&nbsp;&nbsp;ansible python module location =  
/Users/dick.visser/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ansible  
&nbsp;&nbsp;executable location = /Users/dick.visser/.pyenv/versions/3.9.6/bin/ansible  
&nbsp;&nbsp;python version = 3.9.6 (default, Aug 11 2021, 12:13:01) [Clang  
12.0.5 (clang-1205.0.22.11)]

dick.visser@ams-049 ~ % export ANSIBLE\_CONFIG=/opt/ansible.cfg  
dick.visser@ams-049 ~ % ansible --version  
ansible 2.10.12  
&nbsp;&nbsp;config file = /opt/ansible.cfg  
&nbsp;&nbsp;configured module search path =  
['/Users/dick.visser/.ansible/plugins/modules',  
'/usr/share/ansible/plugins/modules']  
&nbsp;&nbsp;ansible python module location =  
/Users/dick.visser/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ansible  
&nbsp;&nbsp;executable location = /Users/dick.visser/.pyenv/versions/3.9.6/bin/ansible  
&nbsp;&nbsp;python version = 3.9.6 (default, Aug 11 2021, 12:13:01) [Clang  
12.0.5 (clang-1205.0.22.11)]

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [September 22, 2021, 7:33pm UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/3 "2021-09-22T19:33:53Z")

</div>

hei Dick,

thx for your getting back to me

sorry, I was not clear enough obviously. The real-life .cfg file I am pointing at naturally. Maybe my understanding is mislead … all best Gunnar

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 22, 2021, 8:23pm UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/4 "2021-09-22T20:23:01Z")

</div>

> I assume the file name (everything preceding the .cfg ending) can be chosen freely and does not require the string 'ansible' being part of it, right? Still, same as you even if I can validate the existence of the ANSIBLE\_CONFIG variable it does not show via ansible --version neither.

Well it works fine here, also for a file with the ansible substring:

$ export ANSIBLE\_CONFIG=/opt/project.cfg  
$ ansible --version | head -2  
ansible 2.10.12  
&nbsp;&nbsp;config file = /opt/project.cfg

unset ANSIBLE\_CONFIG  
$ ansible --version | head -2  
ansible 2.10.12  
&nbsp;&nbsp;config file = /Users/dick.visser/.ansible.cfg

> Maybe I get the understanding of hierarchy not quite right? I was thinking that once set the ANSIBLE\_CONFIG environment variable would overrule all other (fallback) configuration files. That would make much sense to me but maybe the variable is the least mighty one and not the boss in the ring as I thought?

As the above example shows (and as the docs at  
[https://docs.ansible.com/ansible/latest/installation\_guide/intro\_configuration.html#environmental-configuration](https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html#environmental-configuration)  
state):

"Ansible also allows configuration of settings using environment  
variables. If these environment variables are set, they will override  
any setting loaded from the configuration file."

So, if this does NOT work for you, then your environment is wrong  
(wrong variable name/typo?). Or maybe the way you execute the command  
is non standard, shell issues, etc.

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [September 23, 2021, 5:42am UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/5 "2021-09-23T05:42:08Z")

</div>

hello

ok I got it … my understanding of environment variables was not sufficient obviously I thought was proof enough for this to work in the current shell/context and (which in my usecase was not required or even unwanted). thanks for clarifying best Gunnar

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [September 23, 2021, 5:51am UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/6 "2021-09-23T05:51:10Z")

</div>

> hello
> 
> > Well it works fine here, also for a file with the ansible substring:  
> > $ export ANSIBLE\_CONFIG=/opt/project.cfg $ ansible --version | head -2 ansible 2.10.12 config file = /opt/project.cfg
> 
> ok I got it ... my understanding of environment variables was not sufficient obviously
> 
> I thought
> 
> &nbsp;&nbsp;&nbsp;&nbsp;$ ANSIBLE\_CONFIG=/opt/project.cfg  
> &nbsp;&nbsp;&nbsp;&nbsp;$ echo $ANSIBLE\_CONFG  
> &nbsp;&nbsp;&nbsp;&nbsp;/opt/project.cfg
> 
> was proof enough for this to work in the current shell/context and \*you only needed the \*\*'\*\*export'\*\*to make the VARIABLE universal and permanent\* (which in my usecase was not required or even unwanted).
> 
> thanks for clarifying  
> best Gunnar

You don't need export for one time usage:

ANSIBLE\_CONFIG=/opt/project.cfg ansible ...

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![steve\_missoh](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@steve\_missoh](https://forum.ansible.com/u/steve_missoh)\
**Post date:** [September 23, 2021, 9:24am UTC](https://forum.ansible.com/t/problems-to-address-a-configuration-via-ansible-config/35775/7 "2021-09-23T09:24:55Z")

</div>

Hi,  
I dont think that should be your case but just be also aware that:  
Ansible will not automatically load a config file from the current working directory if the directory is world-writable  
Regards.
