title: ansible: specifying directory path using variable
body: <p>My Task: Generate jinja2 templates</p>
  
  <p>Challenge: i wanted to make my playbook/roles independent, and usable in any server irrespective of their HOME directory name, So i have stored the $HOME path into a variable and use that directory location variable to access jinja2 source files.. $HOME stored variable works fine in all tasks, but i am getting error while i use it inside <code>template</code> module"</p>
  
  <p>my role structure.. </p>
  
  <pre><code>roles/
  └── my_role
      ├── defaults
      │   ├── main
      │   │   └── input.yml
      │   └── main.yml
      ├── files
      │   ├── conf
      │   │   └── test.yml
      ├── handlers
      │   └── main.yml
      ├── meta
      │   └── main.yml
      ├── README.md
      ├── tasks
      │   ├── data-input.yml
      │   ├── main.yml
      ├── templates
      │   ├── DIR1
      │   │   ├── PATH1
      │   │   │   ├── file1
      ├── tests
      │   ├── inventory
      │   └── test.yml
      └── vars
          ├── main
          │   └── input.yml
          └── main.yml
  </code></pre>
  
  <p>and my task for generating jinja2 templates..</p>
  
  <pre><code>---
    - include_vars: vars/main/input.yml
  
    - name: Generate templates
      template:
          src: {{ home }}/roles/my_role/templates/DIR1/PATH1/file1
          dest: {{ home }}/roles/my_role/templates/DIR1/PATH1/file2
  </code></pre>
  
  <p><code>{{ home }}</code> stands for <code>/home/ansible</code> that i have stored it to name <code>home</code> using $HOME linux variable.</p>
  
  <p><strong>Getting Error:</strong></p>
  
  <pre><code>ERROR! Syntax Error while loading YAML.
    did not find expected key
  
  The error appears to be in '/home/ansible/roles/my_role/tasks/data_input.yml': line 6, column 24, but may
  be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
  
      template:
          src: {{ home }}/roles/my_role/templates/DIR1/PATH1/file1
                         ^ here
  </code></pre>
  
  <p>i have even tried <code>templates/DIR1/PATH1/file1</code> directory only. but no luck. 
  It works fine when i specify full directory path <code>/home/ansible/roles/my_role/templates/DIR1/PATH1/file1</code> in both <code>src</code> and <code>dest</code>.. </p>
  
  <p>please help.</p>
  
  <p>thanks in advance..</p>