top of page

Use of all:vars in Ansible

In Ansible, all:vars refers to the section in an inventory file where you can define variables that apply to all hosts in your inventory. This is a convenient way to set variables that are shared among all hosts without having to repeat them for each host.

Here is an example of how you can use of all:vars in Ansible inventory file:

[root@siddhesh ~]# cat inventory
[jenkinshost] ansible_host= ansible_python_interpreter=/usr/bin/python3 ansible_host= ansible_python_interpreter=/usr/bin/python3

[root@siddhesh ~]#

In this example:

1. ansible_ssh_user and ansible_ssh_pass are defined under [all:vars].

2. The variables defined in [all:vars] apply to all hosts in the inventory.

3. jenkinshost is a group that includes specific hosts ( and, and they inherit the variables from [all:vars].

So, all hosts in the inventory, including and will have the specified variables (ansible_ssh_user, ansible_ssh_pass).

This approach can help you avoid duplicating variables across multiple host entries in the inventory file, making it easier to manage and update common configurations. Keep in mind that variables defined in a specific host entry or group will override those defined in [all:vars] if there's a conflict.

bottom of page