title: What's the difference between defaults and vars in an Ansible role?
body: <p>When creating a new Ansible role, the template creates both a <code>vars</code> and a <code>defaults</code> directory with an empty <code>main.yml</code> file. When defining my role, I can place variable definitions in either of these, and they will be available in my tasks.</p>
  
  <p>What's the difference between putting the definitions into <code>defaults</code> and <code>vars</code>? What should go into <code>defaults</code>, and what should to into <code>vars</code>? Does it make sense to use both for the same data?</p>
  
  <p>I know that there's a difference in precedence/priority between the two, but I would like to understand what should go where.</p>
  
  <p>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.</p>
  
  <p>Here's what this would look like:</p>
  
  <pre><code>---
  - directories:
    - foo
    - bar
    - baz
  </code></pre>
  
  <p>I could place this either into the <code>defaults/main.yml</code> or in the <code>vars/main.yml</code>, from an execution perspective, it wouldn't make any difference - but where should it go?</p>