title: Ansible variable: Can I reference a variable within itself?
body: <p>I am writing roles for an ansible playbook.  In the role I have a <code>defaults</code> folder containing a <code>main.yml</code> to define default values for the variables the role uses.  Can I cross-reference within the same object?</p>
  
  <p>For example, I have tried the following:</p>
  
  <pre><code>scripts_config: 
    host_entry:
      dir: "/foo" 
      file: "{{dir}}/config"
      foo: "{{host_entry.dir}}/foo"
      bar: "{{scripts_config.host_entry.dir}}/bar"
  </code></pre>
  
  <p>None of them work.  I tried each of <code>file</code>, <code>foo</code> and <code>bar</code> one at a time:</p>
  
  <ul>
  <li><code>file</code> gave <em>The task includes an option with an undefined variable.
  The error was: 'dir' is undefined</em></li>
  <li><code>foo</code> gave <em>The task includes an option with an undefined variable. The error was: 'host_entry' is undefined</em></li>
  <li><code>bar</code> gave <em>An unhandled exception occurred while templating</em></li>
  </ul>
  
  <p>Is it even possible?  </p>
  
  <p>My use case is that I want an object with a directory and several files which would be relative to that in the default set-up.  But if you override the defaults you could specify full paths for one or more of the files, so i don't want the task to assume it's relative.</p>