1 Answer

Aug 24, 2019

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. 

Click here to read more about Ansible
Click here to read more about Insurance

Related questions

Aug 24, 2019 in Ansible
Aug 24, 2019 in Ansible
Aug 24, 2019 in Ansible