title: How to pass variables to included tasks in ansible?
body: <p>I have an ansible file (<code>my_file.yml</code>) that looks something like this:</p>
  
  <pre><code>---
  - name: The name
    hosts: all
    tasks:
  
      - include:my_tasks.yml
        vars:
            my_var: "{{ my_var }}"
  </code></pre>
  
  <p><code>my_tasks.yml</code> looks like this:</p>
  
  <pre><code>- name: Install Curl
    apt: pkg=curl state=installed
  
  - name: My task
    command: bash -c "curl -sSL http://x.com/file-{{ my_var }} &gt; /tmp/file.deb"
  </code></pre>
  
  <p>I'd like to pass <code>my_var</code> as a command-line argument to ansible so I do like this:</p>
  
  <pre><code>ansible-playbook my_file.yml --extra-vars "my_var=1.2.3"
  </code></pre>
  
  <p>But I end up with the following error:</p>
  
  <pre><code>... Failed to template {{ my_var }}: Failed to template {{ my_var }}: recursive loop detected in template string: {{ my_var }}
  </code></pre>
  
  <p>If I the <code>vars</code> in <code>my_file.yml</code> to look like this:</p>
  
  <pre><code>- include:my_tasks.yml
    vars:
        my_var: "1.2.3"
  </code></pre>
  
  <p>it works! I've also tried changing the variable name to something that is not equal to <code>my_var</code>, for example:</p>
  
  <pre><code>- include:my_tasks.yml
    vars:
        my_var: "{{ my_var0 }}"
  </code></pre>
  
  <p>but then I end up with an error. It seems to me that the variable is not expanded and instead the string <code>"{{ my_var }}"</code> or <code>{{ my_var0 }}</code> is passed to <code>my_tasks.yml</code>. How do I solve this?</p>