What are the variable scopes in Ansible?
IntermediateConceptVariables, Facts and Precedence
Answer
- Global: config settings, environment, and
-eextra vars - Play:
vars,vars_files,roles - Host: inventory host and group vars, facts, registered variables and
set_fact, which stay with a host across plays in the same run - Block and task:
varsset on them live only inside
Registered and set_fact values persist for the host for the rest of the run, including later plays. Task vars disappear after the task.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner