Ansible: Configuration file

Ansible_Logo

When executing a playbook, ansible uses certain values mentioned in the “ansible.cfg” file. This includes the location of “inventory” file, etc.

The “ansible.cfg” file can be present in any of the following locations, and the priority of the one selected goes higher in the below sequence:

  1. In the default location “/etc/ansible/ansible.cfg”
  2. In the home folder of the user executing the playbook which is “~./ansible.cfg”
  3. In the folder from where the playbook is executed. That is “./ansible.cfg”
  4. The ansible configuration file path mentioned in CLI command “ANSIBLE_CONFIG=<path>”

An example of a typical ansible.cfg file is as follows:

==== ====

[defaults]
inventory = ./inventory
remote_user = user
ask_pass = false

[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false

==== ====

Configurable items in the [defaults] section are as follows:

  • inventory = ./inventory
  • role_path = ./role
  • collections_paths = ./collections
  • remote_user = admin
  • become = true

The configurable items in the [privilege_escalation] are as follows:

  • become = true
  • become_method = sudo
  • become_user = root
  • become_ask_pass = false