Ansible 6 Understanding host_vars and group_vars
In this post, we will discuss the possible options for ansible variables precedence, Experiment with few host_vars, group_vars, and their variable precedence. You can specify the variables along with the host inside your inventory itself. Ansible host_vars and group_vars and usage options The command-line variable will be the highest priority. To test the variable precedence, top priority extra vars ansible -i "node1," all \ -e "var1=VybhavaTechnologies" \ -m debug -a 'msg={{ var1 }}' Here -i use the target host and the group name to define an extra variable that will have the highest priority. Using debug module we can get the var1 value using jinja format to print. ansible extra variables highest precedence Let's see the following example: Create the inventory.yml file in "dev" directory. inventory.yml all: children: common: children: webserver: hosts: node[1:2]: ...