- In this video, I will tell you about ansible.cfg,
a convenient configuration file
that helps you to set some default values
for your current product or for all of your system.
So when you are managing assets with Ansible,
you will always need to provide different settings.
And these settings can be provided at different levels.
You can put them on the command line.
That is what we have been doing so far.
You can put them in playbooks,
which you will learn about later,
or in the ansible.cfg.
If you are going to work with ansible.cfg,
a default ansible.cfg is provided
in etc/ansible/ansible.cfg.
But you can also create ansible.cfg files
in project directories.
Be aware that if you create an ansible.cfg file
in the project directory,
then that file will always be used.
And if that file exists,
the settings in etc/ansible/ansible.cfg
are not considered at all.
So settings that are made at a more specific level
will always overwrite the generic settings.
Now, let me demonstrate how to use an ansible.cfg
by looking at the default configuration,
but also by looking at an example
from the course Git Repository.
So to start with, I would like to show you
etc/ansible/ansible.cfg,
which is a configuration file
in which you can find all the different parameters.
And there's a lot of parameters.
As you can see, 490 lines in total.
And this is what you can do.
I would like to show you parameters that matter,
but first ansible --version.
Ansible --version is showing you
which configuration file is currently used.
Now we are going to access the course Git Repository.
Before I can, I need sudo dnf install -y git
because that package is not available by default.
And then I can use git clone
https://github.com/sandervanvugt/ansiblecvc.
That's short for Ansible complete video course.
And now if we get into this Ansible CVC,
we see different directories.
Now the thing that matters is the ansible.cfg.
What is that?
Well, that is a configuration file that contains
all the settings that we need.
This is kind of minimal.
So we have a default section.
In a default section, we identified the default options,
including inventory set to inventory,
or remote user set to ansible,
host key checking is false.
You remember the host key checking
that was a failure because of the SSH host keys?
Host key checking is false
makes sure that we won't see that failure anymore.
Inventory is inventory
is looking for a local file with the name inventory.
Remote user is ansible
is expecting a remote user
with the name Ansible to be present.
And then we have privilege escalation
where we set becomes true.
This is what makes it.
We don't have to use -B anymore.
Become method is sudo, become user is root,
and become ask pass is false.
We are not going to prompt for a become password
because this assumes
that password-less privilege escalation is possible.
Now let's run this commands and what is going to happen?
Well, you can see all the parameters
as defined in the ansible.cfg are applied automatically.
So I don't need to specify anything
on the command line anymore.
But hey, what is happening if you would specify
it on the command line?
Well easy, then the command line will always win.
That's a generic rule in Ansible,
the most specific setting will always win.