What is the difference between `vars_files` and `include_vars`?
IntermediateConceptVariables, Facts and Precedence
Answer
vars_files is a play keyword, loaded at play start (static), and the files must exist. include_vars is a task that loads a file or directory at run time, so the path can use facts and loops, and it has a higher precedence.
- ansible.builtin.include_vars: "{{ ansible_facts['os_family'] }}.yml"
- ansible.builtin.include_vars:
dir: vars/app
extensions: [yml]
For an OS-specific file with a default fallback, combine it with lookup('ansible.builtin.first_found', ...).
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