Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

block

include_role

ANSIBLE VERSION

ansible 2.4.3.0
config file = /Users/kevinp/Documents/src/cm/ansible/ansible.cfg
configured module search path = [u'/Users/kevinp/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Users/kevinp/Documents/src/cm/ansible/venv2/lib/python2.7/site-packages/ansible
executable location = /Users/kevinp/Documents/src/cm/ansible/venv2/bin/ansible
python version = 2.7.14 (default, Nov 10 2017, 16:16:47) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]

CONFIGURATION

ANSIBLE_PIPELINING(/Users/kevinp/Documents/src/cm/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/Users/kevinp/Documents/src/cm/ansible/ansible.cfg) = [u'/Users/kevinp/Documents/src/cm/ansible/hosts.py']
DEFAULT_TIMEOUT(/Users/kevinp/Documents/src/cm/ansible/ansible.cfg) = 30

OS / ENVIRONMENT

macOS control machine, CentOS 7.4 guest

SUMMARY

When using the block task, with an embedded include_role task, it appears that any variables defined within the block don't get propagated to handlers that run as part of the included role.

STEPS TO REPRODUCE

Create a task with a block declaration that looks like this:

- block:
- include_role:
name: my_test_role
vars:
my_data: "Sample Number 1"

Create a new role named my_test_role with the following task

- debug:
msg: "my_data in role is {{ my_data }}"
notify: run my handler
changed_when: true

Add a handler to the my_test_role with the following declaration

- name: run my handler
debug:
msg: "my_data in handler is {{ my_data }}"

run the task

EXPECTED RESULTS

You should see 2 debug messages being printed, something like as follows:

"my_data in role is Sample Number 1"

"my_data in handler is Sample Number 1"

ACTUAL RESULTS

The first debug message gets printed as expected, but the second one - the one from the handler - fails due to an undefined variable, something like this:

TASK [role : debug] *****************************
changed: [kspjenkins] => {
"msg": "my_data in role is Sample Number 1"
}

RUNNING HANDLER [ : run my handler] **********************************************
FAILED! => {"msg": "The task includes an option with an undefined variable...."}`

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

import_role

ANSIBLE VERSION

ansible 2.6.0 (devel 8743b20c8e) last updated 2018/02/13 17:38:47 (GMT +200)
config file = /home/nikos/Projects/ansible-demo/ansible.cfg
configured module search path = ['/home/nikos/Projects/ansible-demo/ansible/lib/modules']
ansible python module location = /home/nikos/Projects/ansible/lib/ansible
executable location = /home/nikos/Projects/ansible/bin/ansible
python version = 3.6.4 (default, Jan 5 2018, 02:35:40) [GCC 7.2.1 20171224]

CONFIGURATION

OS / ENVIRONMENT

SUMMARY

I am running import_role against a just-above created instance on google cloud. The role runs fine on the distant host, but the role handlers (just a win_reboot task), runs against my localhost.

STEPS TO REPRODUCE

This is the tasks that I use:

- gce:
name: custom-windows-image
disk_auto_delete: no
disk_size: "{{ win_server.disk_size }}"
external_ip: ephemeral
image_family: windows-2016
ip_forward: yes
machine_type: n1-highcpu-4
metadata: {}
# TODO change this to 'default'
network: "{{ project_facts.network.name }}"
subnetwork: "{{ win_server.subnet }}"
zone: "{{ win_server.zone }}"
tags: custom-windows-image
register: win_instance
- command: >-
gcloud beta compute reset-windows-password
--quiet
--user="{{ win_server.user }}"
--zone="{{ win_server.zone }}"
custom-windows-image
register: win_instance_password
until: win_instance_password.rc != 1
failed_when: false
retries: 5
- add_host: &winrm
hostname: win_instance
ansible_host: "{{ win_instance.instance_data[0].public_ip }}"
ansible_connection: winrm
ansible_port: 5986
ansible_winrm_server_cert_validation: ignore
ansible_winrm_transport: ntlm
ansible_user: "{{ win_server.user }}"
ansible_password: "{{ win_instance_password.stdout_lines[1] | regex_replace('password:[\\s]*([^s]*)', '\\1') }}"
- gce_firewall:
name: custom-windows-image
network: "{{ project_facts.network.name }}"
allowed: udp:3389;tcp:3389;tcp:5986;icmp
src_ranges: "{{ project_facts.local.address }}/32"
target_tags: custom-windows-image
- wait_for_connection:
delegate_to: custom-windows-image
vars: *winrm
- import_role:
name: ansible-windows-setup
private: yes
vars:
windows_setup_hostname: "{{ win_server.name }}"
delegate_to: win_instance

EXPECTED RESULTS

The role handler should be executed against the windows instance and reboot it.

ACTUAL RESULTS

RUNNING HANDLER [ansible-windows-setup : Reboot windows] ************************************
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: nikos
<127.0.0.1> EXEC (Get-WmiObject -ClassName Win32_OperatingSystem).LastBootUpTime
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"msg": "win_reboot: failed to get host uptime info, rc: 1, stdout: b'', stderr: b\"/bin/bash: -c: line 0: syntax error near unexpected token `.LastBootUpTime'\\n/bin/bash: -c: line 0: `(Get-WmiObject -ClassName Win32_OperatingSystem).LastBootUpTime'\\n\"",
"reboot": false
}
META: ran handlers