<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">import_tasks</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.1.0
  config file = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/git/ansible/ansible.cfg
  configured module search path = [u'/home/sumit/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/venv/local/lib/python2.7/site-packages/ansible
  executable location = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/venv/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]"><pre class="notranslate"><code class="notranslate">ansible 2.4.1.0
  config file = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/git/ansible/ansible.cfg
  configured module search path = [u'/home/sumit/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/venv/local/lib/python2.7/site-packages/ansible
  executable location = /mnt/c/Users/sumitkumar/Desktop/DGX-Upgrade/Ansible/venv/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">HOST_KEY_CHECKING(/foo/project/ansible.cfg) = False</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">The following documentation states that I can pass a variable to an imported or included task like <code class="notranslate">- import_tasks: wordpress.yml wp_user=timmy</code>. However, it only works for <code class="notranslate">include_tasks</code> and not when I use <code class="notranslate">import_tasks</code>. When using <code class="notranslate">import_tasks</code> in the aforementioned way, I get an exception that the passed variable is undefined - as can also be seen in the error section below.</p>
<p dir="auto">Like I said, the same code works if I swap <code class="notranslate">import_tasks</code> with <code class="notranslate">include_tasks</code></p>
<p dir="auto">Here's the document I'm referring to: <a href="https://docs.ansible.com/ansible/2.4/playbooks_reuse_includes.html#including-and-importing-task-files" rel="nofollow">https://docs.ansible.com/ansible/2.4/playbooks_reuse_includes.html#including-and-importing-task-files</a></p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<ol dir="auto">
<li>Have a playbook under tasks/abc.yml that relies on a variable that's not defined in vars, like:</li>
</ol>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: echo
  shell: &quot;echo {{ my_special_var }}"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">echo</span>
  <span class="pl-ent">shell</span>: <span class="pl-s"><span class="pl-pds">"</span>echo {{ my_special_var }}</span></pre></div>
<ol start="2" dir="auto">
<li>In your master playbook.yml, call the first task by adding this line:<br>
<code class="notranslate">import_tasks: tasks/abc.yml my_special_var=Hello</code></li>
</ol>

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

<p dir="auto">The task is imported and the variable from the master playbook gets passed.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto"><code class="notranslate">...exception type: &lt;class 'ansible.errors.AnsibleUndefinedVariable'&gt;\nexception: 'my_special_var' is undefined</code></p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.8.2</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">OSX 10.8.5</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Fact gathering fails when cloud module deletes server and roles play is called with a when conditional.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Assuming utilization of a cloud module such as 'rax', you can set the count to 0 to remove the servers and then call out to roles, as such:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Build an exact count of cloud servers with incremented names
  hosts: local
  gather_facts: False
  tasks:
    - name: Server build requests
      local_action:
        module: rax
        credentials: ~/.raxpub
        name: test%03d.example.org
        flavor: performance1-1
        image: ubuntu-1204-lts-precise-pangolin
        state: present
        count: 0
        exact_count: yes
        group: webservers
        wait: yes
      register: rax

- name: Setup nginx
  user: root
  hosts: webservers
  vars:
   operation: &quot;{{ wsoperation }}&quot;
  roles:
    - { role: nginx, when: operation == 'create' }"><pre class="notranslate"><code class="notranslate">- name: Build an exact count of cloud servers with incremented names
  hosts: local
  gather_facts: False
  tasks:
    - name: Server build requests
      local_action:
        module: rax
        credentials: ~/.raxpub
        name: test%03d.example.org
        flavor: performance1-1
        image: ubuntu-1204-lts-precise-pangolin
        state: present
        count: 0
        exact_count: yes
        group: webservers
        wait: yes
      register: rax

- name: Setup nginx
  user: root
  hosts: webservers
  vars:
   operation: "{{ wsoperation }}"
  roles:
    - { role: nginx, when: operation == 'create' }
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">It would expected that the when clause should trigger prior/during the gather facts call thus adhering to the conditional and passing tests.</p>
<p dir="auto">I call this a bug because I assume no operations should happen for a play unless the conditional is met, this includes fact gathering.</p>
<p dir="auto">Besides having a separate playbook with duplicated server logic, which defeats the purpose of this modules benefits, I do not see a proper work around.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">Gather facts is triggered before the when operation is analyzed causing failure.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [webser-backend01] =&gt; SSH encountered an unknown error during the connection"><pre class="notranslate"><code class="notranslate">fatal: [webser-backend01] =&gt; SSH encountered an unknown error during the connection
</code></pre></div>