problems to address a configuration via ANSIBLE_CONFIG

655 views
Skip to first unread message

dulh...@mailbox.org

unread,
Sep 22, 2021, 1:53:15 PM9/22/21
to ansible...@googlegroups.com
hi everybody,

Ansible novice here from Germany

I learned that setting an environment variable for ANSIBLE_CONFIG (like ANSIBLE_CONFIG=/path/to/any.cfg) would make the defined file the preferred configuration file.
However I am still not able to get this working and I am using a fallback configuration file (~/ansible.cfg) for ad-hoc commands as well as per playbook execution.

can anybody clarify what I did misunderstand in this logic?
$ ansible --version
ansible [core 2.11.4]
  config file = /home/username/AnsiblePlayground/ansible.cfg
  configured module search path = ['/home/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/username/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.7 (default, Aug 31 2021, 13:28:12) [GCC 11.1.0]
  jinja version = 3.0.1
  libyaml = True



Dick Visser

unread,
Sep 22, 2021, 2:40:11 PM9/22/21
to ansible...@googlegroups.com
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
config file = /Users/dick.visser/.ansible.cfg
configured module search path =
['/Users/dick.visser/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location =
/Users/dick.visser/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ansible
executable location = /Users/dick.visser/.pyenv/versions/3.9.6/bin/ansible
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
config file = /opt/ansible.cfg
configured module search path =
['/Users/dick.visser/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location =
/Users/dick.visser/.pyenv/versions/3.9.6/lib/python3.9/site-packages/ansible
executable location = /Users/dick.visser/.pyenv/versions/3.9.6/bin/ansible
python version = 3.9.6 (default, Aug 11 2021, 12:13:01) [Clang
12.0.5 (clang-1205.0.22.11)]




On Wed, 22 Sept 2021 at 19:53, dulhaver via Ansible Project
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2b1ac2a8-3121-1d78-0cfe-e77f73382231%40mailbox.org.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

dulh...@mailbox.org

unread,
Sep 22, 2021, 3:34:14 PM9/22/21
to ansible...@googlegroups.com
hei Dick,

thx for your getting back to me


On 22.09.21 20:39, Dick Visser wrote:
I just tried this out and apparently the path you specify for
ANSIBLE_CONFIG has to actually exist:
sorry, I was not clear enough obviously. The real-life .cfg file I am pointing at does exist naturally.

Maybe my understanding is mislead ...
  • 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.
  • 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?

all best
Gunnar

Dick Visser

unread,
Sep 22, 2021, 4:23:26 PM9/22/21
to ansible...@googlegroups.com
On Wed, 22 Sept 2021 at 21:34, dulhaver via Ansible Project
<ansible...@googlegroups.com> wrote:

> 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
config file = /opt/project.cfg

unset ANSIBLE_CONFIG
$ ansible --version | head -2
ansible 2.10.12
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
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.

dulh...@mailbox.org

unread,
Sep 23, 2021, 1:42:26 AM9/23/21
to ansible...@googlegroups.com
hello


On 22.09.21 22:23, Dick Visser wrote:
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
$ ANSIBLE_CONFIG=/opt/project.cfg
$ echo $ANSIBLE_CONFG
/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

Stefan Hornburg (Racke)

unread,
Sep 23, 2021, 1:51:31 AM9/23/21
to ansible...@googlegroups.com
On 23/09/2021 08:42, dulhaver via Ansible Project wrote:
> hello
>
> On 22.09.21 22:23, Dick Visser wrote:
>> 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
>
> $ ANSIBLE_CONFIG=/opt/project.cfg
> $ echo $ANSIBLE_CONFG
> /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
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/03fb1eb2-b975-2e34-d12b-65f17922fec3%40mailbox.org <https://groups.google.com/d/msgid/ansible-project/03fb1eb2-b975-2e34-d12b-65f17922fec3%40mailbox.org?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

OpenPGP_0x5B93015BFA2720F8.asc
OpenPGP_signature

steve missoh

unread,
Sep 23, 2021, 5:24:55 AM9/23/21
to Ansible Project
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.

Reply all
Reply to author
Forward
0 new messages