Ansible Configuration Settings
Let's dive into the common settings that can be configured in the ansible.cfg file.
Hosts File Location (
inventory):The
inventorysetting specifies the location of your hosts file. This file lists the hosts (servers or devices) that Ansible will manage.Example:
[defaults] inventory = /etc/ansible/hostsIn this example, Ansible will use the standard
/etc/ansible/hostsfile as the inventory.
Roles Path (
roles_path):The
roles_pathsetting defines where Ansible looks for roles. Roles are reusable playbooks that encapsulate specific functionality.Example:
[defaults] roles_path = /path/to/your/custom_rolesHere, Ansible will search for roles in the specified directory.
Parallel Processes (
forks):The
forkssetting determines the number of parallel processes Ansible uses when executing tasks.Example:
[defaults] forks = 10In this case, Ansible will run up to 10 tasks concurrently.
Privilege Escalation (
become):Privilege escalation allows Ansible to execute tasks with elevated permissions (e.g., using
sudo).Example:
[privilege_escalation] become = TrueNow Ansible will use privilege escalation when needed.
SSH Arguments (
ssh_args):The
ssh_argssetting allows you to add additional SSH arguments.Example:
[ssh_connection] ssh_args = -o ForwardAgent=yesHere, Ansible will forward the SSH agent for better authentication.
Colorized Output (
color):The
colorsetting controls whether Ansible displays colorized output.Example:
[defaults] color = autoAnsible will automatically enable color if the terminal supports it.
You can customize your ansible.cfg based on your environment and requirements. Let's create a practical example of a custom ansible.cfg file that you might use in a production environment:
Here's a breakdown of the key settings:
inventory: Points to your inventory file (usually/etc/ansible/hosts).log_pathandlog_file: Specify where Ansible logs should be stored.remote_user: Set the default SSH user for connections.color: Enables colorized output for readability.library: Defines the location of custom modules.forksandtimeout: Control performance-related settings.host_key_checking: Disables host key checking (use with caution).retry_files_enabledandmax_retries: Configure task retries.[defaults]section: Additional global settings.
Last updated