Categories

Category cover

Automation
155 posts

Category cover

Learning paths
119 posts

Category cover

CISO
22 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
18 posts

Category cover

Infrastructure
12 posts

Category cover

OT/ICS
5 posts

Category cover

Books
3 posts

Category cover

UNetLab
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Ansible configuration

Andrea Dainese
August 05, 2024
Post cover

Ansible typically works out-of-the-box without requiring additional configuration. However, advanced usage might necessitate some customizat

Ansible typically works out-of-the-box without requiring additional configuration. However, advanced usage might necessitate some customization. Ansible can be configured through files or variables.

For example, the DEFAULT_HOST_LIST parameter defines the inventory file. The official documentation  specifies:

  • Default: The default value if not specified otherwise (/etc/ansible/hosts).
  • INI: How to specify the parameter in an INI configuration file (in this case, the section is [defaults] and the parameter is inventory).
  • Environment: The environment variable name to specify this parameter (ANSIBLE_INVENTORY).

If you choose to configure Ansible via INI files, you have four options:

  • Use the file at /etc/ansible/ansible.cfg
  • Use the file ~/.ansible.cfg in the home directory
  • Use the file ./ansible.cfg in the current directory
  • Use the file defined by the ANSIBLE_CONFIG environment variable

The DEFAULT_HOST_LIST parameter can also be specified on the command line with -i. Additionally, some parameters can be defined within a playbook.

Ansible uses a precedence  to determine which parameter value to use if it is specified multiple times. The order is:

  • Configuration settings
  • Command-line options
  • Playbook keywords
  • Variables

Lower items in the list override higher ones.

There are handy utilities to get general and specific information about your environment:

  • ansible-config list: Lists all possible variables and how to configure them.
  • ansible-config dump: Prints current values for each variable.
  • ansible-config init > ansible.cfg: Creates a sample configuration file, comprehensive but complex.
  • ansible-config view: Verifies and prints the current configuration.

Continue reading the post on Patreon .