ansible.cfg overrides

Hello,

We are using multiple ansible playbook repositories in our company. While we want to make some configuration directives local only for a specific repository, there are some which need to be defined for every current and future repo used in our setup.

A fine example is a log_path directive. Let’s say that we want to log every future ansible command run on a master machine to a /var/log/ansible.log which is independent of the repository from which the run was made. This is why I added the following lines to /etc/ansible/ansible.cfg:
[defaults]
log_path = /var/log/ansible.log

However, all directives defined in this file are being ignored, when ${PWD}/ansible.cfg configuration file is present.

I’ve prepared a small patch to deal with this issue: https://github.com/D3DeFi/ansible/commit/09973901057084f6d06f989ff9b2915a8390e57c but I am not sure if it is a good idea to submit it as a feature_request or bugfix, or if to submit it at all. Bugfix, because this ‘override’ behavior is standard for many other tools and I think it should be default for ansible as well.

Can you guys please provide your opinion on this ? :slight_smile: Is this even a good idea or does ansible read only one ansible.cfg file for purpose ?

Thanks,
Dusan

It is specifically documented that ansible.cfg files are not merged in the documentation provided at http://docs.ansible.com/ansible/intro_configuration.html

“Ansible will process the above list and use the first file found. Settings in files are not merged”

You could override these values however using env vars. Such as exporting ANSIBLE_LOG_PATH="/var/log/ansible.log" before running your ansible command. This could also be achieved by having a file that you source before running ansible.

Having the configurations merge would like cause issues for a number of people. Such as where I have an ~/.ansible.cfg but for some projects I have a completely different ansible.cfg that may not override all of the settings, but I wouldn’t want them merged.

Thank you for explaining this to me Matt :slight_smile: I somehow managed to overlook line you pointed out.