Ansible Configuration Settings
Let's dive into the common settings that can be configured in the ansible.cfg
file.
Hosts File Location (
inventory
):The
inventory
setting specifies the location of your hosts file. This file lists the hosts (servers or devices) that Ansible will manage.Example:
[defaults] inventory = /etc/ansible/hosts
In this example, Ansible will use the standard
/etc/ansible/hosts
file as the inventory.
Roles Path (
roles_path
):The
roles_path
setting defines where Ansible looks for roles. Roles are reusable playbooks that encapsulate specific functionality.Example:
[defaults] roles_path = /path/to/your/custom_roles
Here, Ansible will search for roles in the specified directory.
Parallel Processes (
forks
):The
forks
setting determines the number of parallel processes Ansible uses when executing tasks.Example:
[defaults] forks = 10
In 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 = True
Now Ansible will use privilege escalation when needed.
SSH Arguments (
ssh_args
):The
ssh_args
setting allows you to add additional SSH arguments.Example:
[ssh_connection] ssh_args = -o ForwardAgent=yes
Here, Ansible will forward the SSH agent for better authentication.
Colorized Output (
color
):The
color
setting controls whether Ansible displays colorized output.Example:
[defaults] color = auto
Ansible 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:
# ansible.cfg
# Set the path to your inventory file (hosts file)
inventory = /etc/ansible/hosts
# Configure logging options
log_path = /var/log/ansible.log
log_file = verbose
# Set the default SSH user
remote_user = myuser
# Enable colorized output
color = auto
# Specify the location of custom modules
library = /usr/local/share/ansible
# Fine-tune performance-related settings
forks = 10
timeout = 30
# Disable host key checking for SSH connections (use with caution)
host_key_checking = False
# Set the default number of retries for failed tasks
retry_files_enabled = False
max_retries = 3
# Enable or disable specific features as needed
[defaults]
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/facts_cache
# Additional settings specific to your environment
# ...
# End of ansible.cfg
Here's a breakdown of the key settings:
inventory
: Points to your inventory file (usually/etc/ansible/hosts
).log_path
andlog_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.forks
andtimeout
: Control performance-related settings.host_key_checking
: Disables host key checking (use with caution).retry_files_enabled
andmax_retries
: Configure task retries.[defaults]
section: Additional global settings.
Last updated