Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

import_tasks

ANSIBLE VERSION

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]

CONFIGURATION

HOST_KEY_CHECKING(/foo/project/ansible.cfg) = False

OS / ENVIRONMENT

N/A

SUMMARY

The following documentation states that I can pass a variable to an imported or included task like - import_tasks: wordpress.yml wp_user=timmy. However, it only works for include_tasks and not when I use import_tasks. When using import_tasks in the aforementioned way, I get an exception that the passed variable is undefined - as can also be seen in the error section below.

Like I said, the same code works if I swap import_tasks with include_tasks

Here's the document I'm referring to: https://docs.ansible.com/ansible/2.4/playbooks_reuse_includes.html#including-and-importing-task-files

STEPS TO REPRODUCE

Have a playbook under tasks/abc.yml that relies on a variable that's not defined in vars, like:

- name: echo
shell: "echo {{ my_special_var }}

In your master playbook.yml, call the first task by adding this line:

import_tasks: tasks/abc.yml my_special_var=Hello

EXPECTED RESULTS

The task is imported and the variable from the master playbook gets passed.

ACTUAL RESULTS

...exception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'my_special_var' is undefined

Issue 2:
Issue Type:

Bug Report

Ansible Version:

1.8.2

Environment:

OSX 10.8.5

Summary:

Fact gathering fails when cloud module deletes server and roles play is called with a when conditional.

Steps To Reproduce:

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:

- 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' }

Expected Results:

It would expected that the when clause should trigger prior/during the gather facts call thus adhering to the conditional and passing tests.

I call this a bug because I assume no operations should happen for a play unless the conditional is met, this includes fact gathering.

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.

Actual Results:

Gather facts is triggered before the when operation is analyzed causing failure.

fatal: [webser-backend01] => SSH encountered an unknown error during the connection