top of page
Writer's pictureSiddhesh Kadam

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]
jenkins.builddevops.com ansible_host=192.168.1.2 ansible_python_interpreter=/usr/bin/python3
jenkins1.builddevops.com ansible_host=192.168.1.3 ansible_python_interpreter=/usr/bin/python3

[all:vars]
ansible_ssh_user=centos
ansible_ssh_pass=P@ssw0rd
[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 (jenkins.builddevops.com and jenkins1.builddevops.com), and they inherit the variables from [all:vars].


So, all hosts in the inventory, including jenkins.builddevops.com and jenkins1.builddevops.com 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.






Commentaires

Noté 0 étoile sur 5.
Pas encore de note

Ajouter une note
bottom of page