Ansible offers the ability to set default settings for how modules and playbooks interact with remote nodes in your inventory. There is a huge list of settings you can add within your Ansible configuration file. Below we cover how to locate your Ansible configuration file and included settings. Managing your Ansible agent on CentOS, Ubuntu, or Debian is a great project for Cloud VPS Hosting.
Locate Ansible Configuration File
- Log into SSH
- Navigate to your Ansible directory
- Edit the Ansible configuration file:
nano ansible.cfg
Ansible Configuration
Below is an explanation of each setting included in our UltraStack Ansible configuration file.
ansible_managed = 'Managed by Ansible, do not edit directly'
When running a task that transfers the configuration file to a remote host, this notice displays to warn that any specified variables will overwrite the original file during transfer.
Enable Callback Plugins
callback_whitelist = profile_tasks, timer
Callback plugins enhance output and actions from Ansible events.
- profile_tasks outputs time to execution for a task, similar to the
time
Linux command - timer outputs time to execution for play stats
Maximum Forks
forks = 25
“Forks” are the maximum amount of hosts Ansible can run tasks against at one time. Lowering the max number for forks decreases the system resources required from the Ansible control node.
Host Key Checking for Authentication
host_key_checking = False
This function checks the key in a remote host’s known_hosts directory for authentication upon first connection to prevent server spoofing. Disabling this forces Ansible tasks to run without requesting this interactive confirmation. The options are “True” or “False.”
Process Polling
internal_poll_interval = 0.01
This sets the interval (in seconds) between internal process polling for an estimated time for completion of a task. Higher values decrease CPU usage. Lower values improve graphical user interface (GUI) responsiveness (e.g. Ansible Tower).
Default Inventory Location
inventory = ./inventory.yml
Setting a default Ansible inventory location negates the need to define it each time you run a module or playbook. Change this if you decide to move your inventory file for security by obfuscation or other reasons.
Cowsay Fun Messages
nocows = 1
Cowsay is a CLI program that shows a cow and fun messages while running tasks. We disable Cowsay by default for a sleek, professional experience. Remove this line to enable cowsay.
Default Callback Plugin For Console Output
stdout_callback = yaml
You can only use one main callback plugin at once. The YAML callback plugin provides human-readable output instead of raw JSON output.
Compression Level for Less Bandwidth
var_compression_level = 9
Compress Ansible modules and variables before transferring them for less bandwidth usage. This can be set between 0-9.
Time Before Timeout
command_timeout = 300
Set how many seconds to wait for a response from a remote node before a task times out.
Convert minutes to seconds with the DuckDuckGo converter.
Time Idle
connect_timeout = 300
Set how many seconds a connection will idle with no activity before closing.
SSH Timeout
timeout = 300
Set how many seconds to wait between SSH connection attempts.
Pipelining
pipelining = True
By default, Ansible connects to the remote host, transfers the module, and executes it using separate connections per module. Pipelining reduces this to one SSH connection per module to improve performance. However, when using sudo
you must disable “requiretty” in /etc/sudoers on remote hosts.
Retries if SSH Connection Fails
retries = 1
Set how many times Ansible retries if an SSH connection fails before signaling a task failed.
Follow our Ansible Education Channel to learn more about IT automation.