Senior
What is the priority order of variables in Ansible? Compare defaults and vars.
sobes.tech AI
Answer from AI
In Ansible, variables have different priorities that determine which values are used in case of conflicts. Specifically, defaults and vars differ in priority:
-
defaultsare variables with the lowest priority. They are usually defined in roles in thedefaults/main.ymlfile. They set default values that are easy to override. -
varsare variables with a higher priority, defined in thevars/main.ymlof roles or invarsblocks within playbooks. They override values fromdefaults.
Thus, if the same variable is defined in both defaults and vars, the value from vars will be used. This allows setting base values and overriding them with more specific settings if needed.