
The ansible-config command with the --version flag can be used to list the location of the Ansible configuration file, ansible.cfg.
ansible-config --version
Something like this should be returned.
ansible-config 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/your_username/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible playbook module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, mm dd yyyy, hh:mm:ss) [GCC 4.8.5 yyyymmdd (Red Hat 4.8.5-39)]
Or, the ansible-playbook command with the -v (verbose) flag can be used.
ansible-playbook foo.yml -v
Something like this should be returned.
Using /etc/ansible/ansible.cfg as config file
Or with the -vv flag.
ansible-playbook foo.yml -vv
Something like this should be returned.
ansible-playbook 2.9.12
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/john.doe/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
It's important to recognize that there can be multiple ansible.cfg files, and the ansible.cfg file higher in this list will take precedence over the ansible.cfg file lower in this list.
- ANSIBLE_CONFIG variable (refer to Ansible - Getting Started with Variables)
- ansible.cfg in the present working directory
- .ansible.cfg in the user home directory (e.g. /home/john.doe/.ansible.cfg)
- /etc/ansible/ansible.cfg
For example, let's say you have both /etc/ansible/ansible.cfg and ansible.cfg in your present working directory. In this scenario, the ansible.cfg file in your present working directory will take precedence over /etc/ansible/ansible.cfg.
~]$ ansible-config --version
ansible-config 2.9.27
config file = /home/john.doe/ansible.cfg
configured module search path = ['/home/john.doe/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.8 (default, Apr 2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
If config file returns None . . .
ansible 2.9.12
config file = None
. . .
Create the /etc/ansible directory if it doesn't exist.
mkdir /etc/ansible
And then create the ansible.cfg file.
touch /etc/ansible/ansible.cfg
Now the ansible-config --version command should return /etc/ansible/ansible.cfg as the Ansible config file.
ansible-playbook 2.9.12
config file = /etc/ansible/ansible.cfg
. . .
The ansible-config list command to view example configuration directives that can be added to ansible.cfg.
ansible-config list
Did you find this article helpful?
If so, consider buying me a coffee over at