# How do we set config file in another place?

**URL:** <https://forum.ansible.com/t/how-do-we-set-config-file-in-another-place/2530>\
**Category:** Get Help\
**Tags:** galaxy-ng\
**Created:** [November 23, 2023, 3:03am UTC](https://forum.ansible.com/t/how-do-we-set-config-file-in-another-place/2530 "2023-11-23T03:03:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanhnguyen](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@lanhnguyen](https://forum.ansible.com/u/lanhnguyen)\
**Post date:** [November 23, 2023, 3:03am UTC](https://forum.ansible.com/t/how-do-we-set-config-file-in-another-place/2530/1 "2023-11-23T03:03:46Z")

</div>

On each project we have each ansible.cnf file.  
When I run playbook file or run ansbile-galaxy command for each project, it always load /etc/ansible/ansible.cfg file, How do we change this config file in another path?

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 23, 2023, 12:33pm UTC](https://forum.ansible.com/t/how-do-we-set-config-file-in-another-place/2530/2 "2023-11-23T12:33:38Z")

</div>

Hey,

Have a look to the [related documentation page / section](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file).

I don’t know for AWX jobs, but assuming each of your project have its own ansible.cfg file in the directory you’re running your playbook, it should be used over the one you have in /etc/ansible/. You could also use the `ANSIBLE_CONFIG` envvar to tell Ansible which config file to use for your run.

Also ask yourself why you need to do that in the first place; if it’s because you want to define roles / collections paths for each job, for instance, then you could also [use envvars](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-roles-path) as well.

Edit: Haven’t seen @utoddl [already answered your question](http://forum.ansible.com/t/how-to-arrange-structure-for-the-case-multiple-projects/2355/21), as you asked in another thread.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 23, 2023, 2:53pm UTC](https://forum.ansible.com/t/how-do-we-set-config-file-in-another-place/2530/3 "2023-11-23T14:53:04Z")

</div>

To expand on @ptn’s comment about environment variables vs. `ansible.cfg` files.

When our group first started using Ansible, we put custom `ansible.cfg` files all over the place, no two of them just alike. We do our playbook development and initial testing on our ssh bastion; final testing and production happen in our AWX instance. With so many different `ansible.cfg` files floating around, getting consistency with each other, and particularly with our AWX instance, was a struggle.

So we abandoned / banned all `ansible.cfg` files besides the one in `/etc/ansible/`, which we tweaked to match our AWX environment as closely as possible. So everybody gets the same, sane, “local” defaults. For those cases where you really do need to customize something, we set an environment variable. The values from environment variables overlay those from the one `ansible.cfg` file, so we get to adjust individual settings without losing the carefully curated set in `/etc/ansible/ansible.cfg`.

To facilitate transitioning from `~/.ansible.cfg` to environment variables, we came up with [ansible-cfg2env](https://gist.github.com/utoddl/216861a76496d9431db3b1cd3936679c), a Python script that uses `ansible-config` underneath to examine settings and preserve any customizations in a form a shell can use. Here’s how it describes itself:

```txt
$ ansible-cfg2env -h
usage: ansible-cfg2env [-h] [-c] [-a]

optional arguments:
  -h, --help show this help message and exit
  -c format for csh/tcsh instead of sh/ksh/bash.
  -a include comments for all settings, not just those differing from their default values.

ansible-cfg2env converts ansible configuration settings from ansible.cfg
format to a format suitable to set the equivalent command shell environment
variables. Given that Ansible ignores system level ansible.cfg files after
finding a user's ~/.ansible.cfg (rather than combining settings from all
found config files), we're now recommending that users use environment
variables to override only those settings they need to change. Settings
from environment variables take precedence over those from found
ansible.cfg files.

Typical usage:
  ansible-cfg2env -a > ~/.ansible.cfg.sh
  mv ~/.ansible.cfg ~/.ansible.cfg-$(date -r ~/.ansible.cfg +%Y-%m-%d)
  echo ". ~/.ansible.cfg.sh" >> ~/.bash_profile
  . ~/.ansible.cfg.sh

```

Since I switched off my `~/.ansible.cfg` as described above, I now customize my Ansible configuration exclusively with environment variables through `~/.ansible.cfg.sh` while still benefiting from the settings curated by our group as preserved in `/etc/ansible/ansible.cfg`.
