<p dir="auto">Issue Type: Bug Report<br>
Ansible Version: 2.0.0.1<br>
Ansible Configuration: nothing changed<br>
Environment: OS X 10.11.2<br>
Summary:</p>
<p dir="auto">Conditional role inclusion in a play still tries to expand variables passed onto this role, even if the role is being skipped</p>
<p dir="auto">Steps To Reproduce:</p>
<p dir="auto">Given a play of this kind:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="...
  roles:
    - { role: some_role,
        some_var: &quot;{{ some_value }}&quot;,
        when: some_value is defined,
        tags: [ tag1, tag2 ]
      }"><pre class="notranslate"><code class="notranslate">...
  roles:
    - { role: some_role,
        some_var: "{{ some_value }}",
        when: some_value is defined,
        tags: [ tag1, tag2 ]
      }
</code></pre></div>
<p dir="auto">when the <code class="notranslate">some_value</code> variable is undefined, one gets an error <code class="notranslate">ERROR! ERROR! 'some_value' is undefined</code> even though the output clearly shows that the role is being skipped:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="skipping: [localhost] =&gt; {&quot;changed&quot;: false, &quot;skip_reason&quot;: &quot;Conditional check failed&quot;, &quot;skipped&quot;: true}"><pre class="notranslate"><code class="notranslate">skipping: [localhost] =&gt; {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
</code></pre></div>
<p dir="auto">Expected Results:</p>
<p dir="auto">The role should be skipped without the error, as was the behaviour of Ansible 1.9.4</p>
<p dir="auto">Actual Results:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="...
TASK [some_role : description of first task in that role] **
task path: /Users/some_user/some/path/to/roles/some_role/tasks/main.yml:2
skipping: [localhost] =&gt; {&quot;changed&quot;: false, &quot;skip_reason&quot;: &quot;Conditional check failed&quot;, &quot;skipped&quot;: true}
ERROR! ERROR! 'some_value' is undefined"><pre class="notranslate"><code class="notranslate">...
TASK [some_role : description of first task in that role] **
task path: /Users/some_user/some/path/to/roles/some_role/tasks/main.yml:2
skipping: [localhost] =&gt; {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
ERROR! ERROR! 'some_value' is undefined
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Files/Template</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.2.0 (stable-2.3 10aa164166) last updated 2017/06/29 18:32:01 (GMT +300)
  config file = /home/user/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]"><pre class="notranslate"><code class="notranslate">ansible 2.3.2.0 (stable-2.3 10aa164166) last updated 2017/06/29 18:32:01 (GMT +300)
  config file = /home/user/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">none</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Lots of application, I install with ansible, are tar archives downloaded with 'maven_artifact' or 'unarchive' modules.<br>
Some of these archives contains templates of configuration files in jinja2 format. I want to be able copy those files to application config directory with replacing jinja2 placeholders and without copying them to my local machine.<br>
Now I have to use module 'replace', but I think it may be more native to use 'template' module with option 'remote_src=yes'</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: Get Snapshot app
  maven_artifact:
    group_id: &quot;{{ component_group_id }}&quot;
    artifact_id: &quot;{{ component_artifact_id }}&quot;
    repository_url: &quot;{{ snapshot_repository }}&quot;
    version: &quot;{{ component_version }}&quot;
    extension: 'tar.gz'
    dest: &quot;{{ some_path }}.tgz&quot;

- name: Extract tarball
  unarchive:
    remote_src: yes
    src: &quot;{{ some_path }}.tgz&quot;
    dest: &quot;{{ app_directory }}&quot;

- name: Copy configuration files
  template:
    remote_src: yes  # &lt;- this is what I want
    src: &quot;{{ app_directory }}/conf_templates/{{ item }}.j2&quot;
    dest: &quot;{{ app_directory }}/conf/{{ item }}&quot;
  with_items: &quot;{{ conf_files }}&quot;"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">Get Snapshot app</span>
  <span class="pl-ent">maven_artifact</span>:
    <span class="pl-ent">group_id</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ component_group_id }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">artifact_id</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ component_artifact_id }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">repository_url</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ snapshot_repository }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">version</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ component_version }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">extension</span>: <span class="pl-s"><span class="pl-pds">'</span>tar.gz<span class="pl-pds">'</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ some_path }}.tgz<span class="pl-pds">"</span></span>

- <span class="pl-ent">name</span>: <span class="pl-s">Extract tarball</span>
  <span class="pl-ent">unarchive</span>:
    <span class="pl-ent">remote_src</span>: <span class="pl-s">yes</span>
    <span class="pl-ent">src</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ some_path }}.tgz<span class="pl-pds">"</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ app_directory }}<span class="pl-pds">"</span></span>

- <span class="pl-ent">name</span>: <span class="pl-s">Copy configuration files</span>
  <span class="pl-ent">template</span>:
    <span class="pl-ent">remote_src</span>: <span class="pl-s">yes  </span><span class="pl-c"><span class="pl-c">#</span> &lt;- this is what I want</span>
    <span class="pl-ent">src</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ app_directory }}/conf_templates/{{ item }}.j2<span class="pl-pds">"</span></span>
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ app_directory }}/conf/{{ item }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ conf_files }}<span class="pl-pds">"</span></span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Files from directory 'conf_templates' should be copied to directory 'conf' with jinja2 filters applied</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Now I can fetch those files to my local machine into temporary directory and then copy them back as templates, or use 'replace' module to replace jinja2 placeholders.</p>