Note: This post presumes that you have completed the steps in the previous posts, starting with Ansible Lab – Getting Started


Sample Files

Did you know that when you installed Ansible it provided inventory and configuration file templates for you? Let’s take a look. On the Ansible server navigate to /etc/ansible and pull up a directory listing


cd /etc/ansible
ls -lah


/etc/ansible/ansible.cfgA template configuration file. By default all content is commented out
/etc/ansible/hostsA template inventory file. By default all content is commented out
/etc/ansible/rolesAn empty folder for storing created roles in


I won’t go through the contents of the ansible.config or hosts files as they are nicely documented inline ( editor: and online by Ansible as well ). However let’s create a simple configuration file to get us going. I am going to rename the ansible.config file and create my own version of it.


mv /etc/ansible/ansible.config /etc/ansible/ansible.config.original
touch /etc/ansible/ansible.config

I have edited my new ansible.config file (using nano) and inserted the following.


The edited ansible.config file


As you can see I have added an inventory entry in, pointing to the inventory file we created earlier. Now I won’t have to specify the -i <inventory_file> each time I use the ansible cli. I have specified the root user as the user to use for sudo operations, for visibility, as well as setting a timeout value for SSH connections.

I can test my new configuration file with the following command


Testing our ansible.config


As you can see I run the first command specifying the inventory file location and this worked fine. I then re-run the command again failing to specify the inventory file. Again the command worked. Ansible successfully read the inventory file path from the ansible.config file which we modified.

Note: Even though we have the inventory file specified in the ansible.config file, we can override this on the command line. Why? We may have another inventory file we want to use for testing








CIO at Sonar, Automation Practice Lead at Xtravirt and guitarist in The Waders. Loves IT, automation, programming, music

%d bloggers like this: