Automate with Ansible: Part 4

Laxfed Paulacy
2 min readJan 10, 2023

Get yourself an ansible config file, bruh!


Ansible Config File

Ansible uses a configuration file called ansible.cfg to set various settings and options. This file is typically located in the /etc/ansible directory, but it can also be placed in the current working directory or in the home directory of the user running the playbook.

The configuration file contains two sections, defaults and ssh_connection, each one containing several key-value pairs.


inventory = /path/to/inventory
remote_user = ansible
private_key = /path/to/private/key

# The directory containing the playbooks
playbook_dir = /path/to/playbooks

# The path to the callback plugins
callback_plugins = /path/to/callback_plugins

# The path to the action plugins
action_plugins = /path/to/action_plugins

# The path to the connection plugins
connection_plugins = /path/to/connection_plugins

# The path to the lookup plugins
lookup_plugins = /path/to/lookup_plugins

# The path to the inventory plugins
inventory_plugins = /path/to/inventory_plugins

# The path to the vars plugins
vars_plugins = /path/to/vars_plugins

# The path to the filter plugins
filter_plugins = /path/to/filter_plugins

# Timeout for the connection
timeout = 30

# Remote port to use
remote_port = 22

# Use ansible-config instead of ansible-inventory when invoked
interpreter_python = /usr/bin/python3

ssh_args = -o ControlMaster=auto -o ControlPersist=60s

In this example, you can find additional options and paths that can be configured in the ansible.cfg file.

  • [defaults] section is where you can set defaults for all other sections in the config file.
  • inventory: This specifies the path to the inventory file that Ansible uses to know which hosts to connect to.
  • remote_user: This specifies the user to connect as when using SSH.
  • private_key: This is the path to the private key to use for authentication when using SSH.
  • playbook_dir: The directory containing the playbooks, this is where Ansible looks for playbooks by default
  • callback_plugins, action_plugins, connection_plugins, lookup_plugins, inventory_plugins, vars_plugins, filter_plugins: These are the path to where ansible can find the corresponding plugin types.
  • timeout: This value sets the timeout (in seconds) for the connection to the remote hosts
  • remote_port: This value sets the port to be used when

You can also have multiple ansible.cfg files in different directories, Ansible will automatically find and use the first config file it finds while searching in the following order:

  • ANSIBLE_CONFIG environment variable.
  • ansible.cfg file in the current working directory
  • ~/.ansible.cfg file in the home directory of the user running ansible-playbook
  • /etc/ansible/ansible.cfg




Laxfed Paulacy

Delivering Fresh Recipes, Crypto News, Python Tips & Tricks, and Federal Government Shenanigans and Content.