Suscríbase al feed

With a fresh installation of Ansible, like every other software, it ships with a default configuration file. This is the brain and the heart of Ansible, the file that governs the behavior of all interactions performed by the control node. In Ansible’s case that default configuration file is (ansible.cfg) located in /etc/ansible/ansible.cfg

Please pay close attention to the line that starts with “# nearly... “ This line details the order of precedence of Ansible, which we will talk about down below, I just wanted to point that out.

 

 

As you can see, the default Ansible configuration file is very large and divided into ten different sections. Each section denoted within the square brackets gives you an idea about this massive configuration file. I will choose a couple of the default parameters to demonstrate how they affect Ansible’s behavior. I highly recommend that you browse through the default configuration file to see the different settings that are available to you. In most cases, to have basic Ansible configuration file going, you can get away with just having the [defaults] and [privilege_escalation] settings, as you will see below. 

 

Ansible is so flexible, and it chooses its configuration file from one of several possible locations on the control node. One use case where this might be useful would be managing a web server and a database server. You might need to gather facts from one host and not on the other one. Having an ansible.cfg in the current project working directory can facilitate this behavior. If we’re going to be working with multiple configuration files, it is important to understand the order of precedence on how it chooses its configuration file; we’ll go through them below.

By default Ansible reads its configuration file in /etc/ansible/ansible.cfg , however this behavior can be altered. The recommended practice is either to have an ansible.cfg in your current project working directory or to set it as an environment variable. One way to determine which configuration file ansible is using is to use the $ansible --version command, you can also run your ansible commands with the -v option.

 

When it comes to the order of precedence, the ANSIBLE_CONFIG  environment variable has the highest precedence. If this environment variable is in your current shell, it will override all other configuration files. Here is one reason you might want to use the environment variable: let’s say you have multiple projects and you want all of them to use one specific configuration file, besides the default one located in /etc/ansible. Setting the environment variable would be a good way to solve this problem. 

The second location on the food chain is to have ansible.cfg in your current working directory. if Ansible doesn’t find a configuration file in the current working directory, it will then look in for an .ansible.cfg file in the user’s home directory, if there isn’t one there either, it will finally grab the /etc/ansible/ansible.cfg.

Read more about optimizing performance for the open-hybrid enterprise.

The ansible-config utility

Use the ansible-config utility to view, list, or dump the various different settings available for Ansible. Running the $ansible-config view utility will print in your standard output your current ansible.cfg content, as you can see, this below outcome is the exact same as the earlier $cat ansible.cfg command above. 

 

Remember how we say earlier if an environment variable is defined, it has the highest precedence? Let’s demonstrate this workflow and use $ansible-config dump to dump all of Ansible current confirmation.

 

In the above example, we set the ANSIBLE_COLOR environment variable to true, and we demonstrated the use of ansible-config dump to dump out Ansible’s current configuration, and then we ran the $ansible-dump command again. As you can see, no colors are being displayed in standard out. Using environment variables is a quick way to tweak non-persistent settings.

Lastly, we can use $ansible-config list command to see a list of all different parameters, their default value, and the different values you can set. 

When it comes to managing Ansible configuration, that’s pretty much all the meats and potatoes. Please reference the official documentation page https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html for more detailed information. I hope you’ve found this quick read useful. 

Connect with Red Hat Services

Learn more about Red Hat Consulting
Learn more about Red Hat Training
Join the Red Hat Learning Community
Learn more about Red Hat Certification
Subscribe to the Training Newsletter
Follow Red Hat Services on Twitter
Follow Red Hat Open Innovation Labs on Twitter
Like Red Hat Services on Facebook
Watch Red Hat Training videos on YouTube
Understand the value of Red Hat Certified Professionals


Sobre el autor

Joe Charles is a container infrastructure consultant with Red Hat.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

Navegar por canal

automation icon

Automatización

Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos

AI icon

Inteligencia artificial

Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar

open hybrid cloud icon

Nube híbrida abierta

Vea como construimos un futuro flexible con la nube híbrida

security icon

Seguridad

Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías

edge icon

Edge computing

Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge

Infrastructure icon

Infraestructura

Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo

application development icon

Aplicaciones

Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones

Original series icon

Programas originales

Vea historias divertidas de creadores y líderes en tecnología empresarial