What is the difference between a role's `defaults/` and `vars/`?
IntermediateConceptVariables, Facts and Precedence
Answer
defaults/main.yml has the lowest precedence, so inventory, play or -e can override it. It is the role's public interface. vars/main.yml has high precedence (level 15) and is hard to override from inventory, so use it for internal constants (such as OS-specific package names) that users should not change.
# roles/nginx/defaults/main.yml
nginx_worker_processes: auto
# roles/nginx/vars/Debian.yml
nginx_pkg: nginx-full
If users cannot override something that they reasonably need to, you put it in the wrong place.
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 are facts and how are they gathered?BeginnerWhat is the difference between `ansible_facts['x']` and the older `ansible_x` variables?Intermediate