Creating an Ansible Config File
In this lesson, you will learn about Ansible Config files and how to create them. It's important for you to know how to create and work with config files as they can save you from having to repeat certain arguments every time you run Ansible. Let's get started!
What is an Ansible Config File?
An Ansible config file tells Ansible about your environment. The ansible-config utility that comes with Ansible allows you to see all the configuration settings you can set inside of this config file. Ansible will search for config files in the following order:
ANSIBLE_CONFIG(environment variable if set)ansible.cfg(in the current directory)~/.ansible.cfg(in the home directory)/etc/ansible/ansible.cfg
We're going to use the ansible.cfg in our current directory to define the default inventory file that should be used when running Ansible in that directory.
Configuring our Custom Inventory as Default
When we ran the ping command earlier, we had to specify the inventory file we want to use with the -i argument like so:
ansible webservers -i inventory -m ping
This is tedious and since you would need to do this every time you ran Ansible, and if we fail to use the -i argument, we see a message like that below, and worst of all, no action is taken by our Ansible controller:
Ansible - No Inventory Found
One way to avoid this issue is by creating an Ansible config file. As we stated before, if there is a file named ansible.cfg in the current directory where you are running your Ansible commands, it will be used as the default config.
Inside that config file, in INI format, we can specify the default inventory setting. We can either create a blank config file with the touch command, or use the ansible-config command to create a fully commented out config file, or do both whi…
No comments yet. Add the first comment to start the discussion.