Bootstrap FreeKB - Ansible - Configuration file (ansible.cfg ansible-config)
Ansible - Configuration file (ansible.cfg ansible-config)

Updated:   |  Ansible articles

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

 

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

 

When an Ansible command is invoked, such as the ansible ad-hoc command or ansible-playbook, the command will use the following order to look for the Ansible configuration file.

  1. ANSIBLE_CONFIG variable (refer to Ansible - Getting Started with Variables)
  2. ansible.cfg in the present working directory
  3. .ansible.cfg in the user home directory (e.g. /home/john.doe/.ansible.cfg)
  4. /etc/ansible/ansible.cfg

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4ab375 in the box below so that we can be sure you are a human.