0 votes
in Ansible by
Define Ansible variables precedence order.

1 Answer

0 votes
by

Here are the variables order of precedence from highest to least.  

# Extra vars or variables supplied in command line of ansible command or playbook. 

# Set_facts or registered variables 

# Include_vars 

# Tasks var ( only for task ) 

# Block vars ( only for tasks in block ) 

# Role vars ( defined in role/vars/main.yml ) 

# Play vars_files 

# Play vars_prompt 

# Play vars 

# Host facts / cached set_facts 

# Playbook host_vars/* 

# Inventory host_vars/* 

# Playbook group_vars/* 

# Inventory group_vars/* 

# Playbook group_vars/all 

# Inventory group_vars/all 

# Role defaults 

         

Basically, anything that goes into “role defaults” (the defaults folder inside the role) is the most malleable and easily overridden. Anything in the vars directory of the role overrides previous versions of that variable in namespace. The idea here to follow is that the more explicit you get in scope, the more precedence it takes with command line -e extra vars always winning. Host and/or inventory variables can win over role defaults, but not explicit includes like the vars directory or an include_vars task. 

Related questions

0 votes
asked Aug 24, 2019 in Ansible by rahulsharma
0 votes
asked Aug 24, 2019 in Ansible by rahulsharma
...