DevOps / Ansible Interview questions
What are the types of variables in Ansible?
Ansible pulls variables from many possible sources, each with a different scope and precedence.
| Source | Typical use |
Role defaults (defaults/main.yml) | Lowest-precedence, overridable fallback values. |
| Inventory / group_vars / host_vars | Environment- or host-specific settings. |
| Play vars / vars_files | Values scoped to a specific playbook run. |
Registered variables (register) | Output captured from a previous task. |
| Facts | Auto-discovered host information. |
Extra vars (-e on the command line) | Highest-precedence, runtime overrides. |
Understanding which source wins matters because the same variable name can be set in several places at once; Ansible resolves this through a well-defined precedence order rather than "last one wins" by file position alone.
More Related questions...