Where can you define variables in Ansible?
BeginnerConceptVariables, Facts and Precedence
Answer
- Inventory (host and group variables,
group_vars/,host_vars/) - Playbook: play
vars,vars_files,vars_prompt, task and blockvars - Roles:
defaults/main.yml,vars/main.yml - At run time:
register,set_fact,include_vars - Command line:
-e key=value,-e @file.yml - Facts collected from the host, and environment via lookups
Pick one home for each variable, usually role defaults for tunables and group_vars for environment-specific values.
More on Variables, Facts and Precedence
How 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?BeginnerWhat is the difference between `ansible_facts['x']` and the older `ansible_x` variables?Intermediate