Ansible – Post – 7 – Ansible config

Spread the love



Ansible - Post - 7 - Ansible config:

In this blog post, we will see how to create the ansible configuration file. There are four different configuration file that ansible will look for before executing the playbook and the order is give below.​​ 


Ansible config – order of operations


  • $ANSIBLE_CONFIG – looks for the ansible config information in the environment variables


  • ./ansible.cfg – looks for the ansible.cfg from the​​ current​​ directory in which you run the playbook


  • ~./ansible.cfg – looks for the hidden ansible.cfg configuration from the home directory of the user who executes the playbook


  • /etc/ansible/ansible.cfg – looks for the configuration file in the​​ ansible installation dirctory.


Please note that ansible environment variable will always precedence and ansible will stop will looking for the .cfg file if it gets the information from the environment variable.


The different configuration settings are given in the below website,


lets taken an example, ​​ we will create “ansible.cfg” in the current directory and we will define the config setting that the host_key_checking=False, this means that ansible will not verify the ~/.ssh/known_hosts file when it tries to execute the command in the target system.​​ 




Lets override this​​ setting​​ ​​ with an environment variable, saying that host_key_checking=True



We will empty the ~/.ssh/known_hosts



Now let’s try to run the ping command on the webservers group, we should get a failed output as the fingerprint is not available in the know_hosts file. It clearly shows that the environment variable has taken precedence.​​ 



Now lets unset the environment variable and try to run the command again.​​ 



Now we get a success message for the ping command.​​ 


Thanks for viewing the post, please post your comments below.

Please Like & Follow us on Facebook & Twitter,

Related posts

Leave a Comment