When creating a new Ansible role, the template creates both a vars
and a defaults
directory with an empty main.yml
file. When defining my role, I can place variable definitions in either of these, and they will be available in my tasks.
What's the difference between putting the definitions into defaults
and vars
? What should go into defaults
, and what should to into vars
? Does it make sense to use both for the same data?
I know that there's a difference in precedence/priority between the two, but I would like to understand what should go where.
Let's say that my role would create a list of directories on the target system. I would like to provide a list of default directories to be created, but would like to allow the user to override them when using the role.
Here's what this would look like:
---
- directories:
- foo
- bar
- baz
I could place this either into the defaults/main.yml
or in the vars/main.yml
, from an execution perspective, it wouldn't make any difference - but where should it go?