What is Ansible Configuration Files Explained with Examples

This article explains about the what is ansible configuration file and management. Before creating playbook, we should have knowledge about what is Ansible and Configuration Files.

You can also visity the below topics.

Ansible Tutorial | What is Ansible | Learning Ansible basics

Ansible Configuration

Configuration File

  • Settings in Ansible parameter via configuration file (ansible.cfg)
  • Default configuration file, /etc/ansible/ansible.cfg, for all the users
  • There may be reasons to change it

[root@myaansible ~]# vi /etc/ansible/ansible.cfg

# config file for ansible — https://ansible.com/
# ===============================================

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first


# some basic default values…

#inventory = /etc/ansible/hosts
#library = /usr/share/my_modules/
#module_utils = /usr/share/my_module_utils/
#remote_tmp = ~/.ansible/tmp
#local_tmp = ~/.ansible/tmp
#plugin_filters_cfg = /etc/ansible/plugin_filters.yml
#forks = 5
#poll_interval = 15
#sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
#transport = smart
#remote_port = 22

Environment Variables

Ansible also allows configuration of settings using environment variables. If set, they override settings loaded from configuration file.


Command Line Options

  • Not all configuration options available via command line, just those deemed most useful or common
  • Settings in command line override those passed through configuration file and environment


Configuration Settings in Ansuble

  • ansible-config utility allows users to see all available configuration settings and their defaults, how to set them, and where current values come from
  • Changes can be made in configuration file
  • Ansible searches for file to use in this order:
  • ANSIBLE_CONFIG (environment variable, if set)
  • ansible.cfg (in current directory)
  • ~/.ansible.cfg (in home directory)
  • /etc/ansible/ansible.cfg
  • First file found is used and all others ignored

Support us: If you like this post, Share with your friends and groups