Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

include_role

ANSIBLE VERSION

$ ansible --version
ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o override

CONFIGURATION

[defaults]
inventory = /etc/ansible/hosts
private_key_file = /home/insecure_private_key
transport = ssh
host_key_checking = False
jinja2_extensions = jinja2.ext.do
gathering = smart
gather_subset = network
roles_path = /usr/share/ansible/roles

/etc/ansible/hosts

[cluster]
thisNode ansible_host=localhost ansible_connection=local
dww

OS / ENVIRONMENT

Ubuntu 14.04

SUMMARY

Using include_role in a loop seems to be executed twice: once with hosts, and another with the specified items.

STEPS TO REPRODUCE

ansible-playbook testPlaybook.yml

---
- hosts: cluster
tasks:
- name: Execute test role
include_role:
name: testrole
allow_duplicates: False
with_items:
- 'one'
...

/usr/share/ansible/roles/testrole/tasks/main.yml

---
- name: Just debugging
debug:
...

EXPECTED RESULTS

I expected to see testrole executed once, since I am only passing a single item to it

PLAY [cluster] *****************************************************************

TASK [setup] *******************************************************************
ok: [thisNode]
ok: [dww]

TASK [Execute test role] *******************************************************

TASK [testrole : Just debugging] ***********************************************
ok: [dww] => {
"msg": "Hello world!"
}
ok: [thisNode] => {
"msg": "Hello world!"
}

ACTUAL RESULTS

I see testrole executed twice

PLAY [cluster] *****************************************************************

TASK [setup] *******************************************************************
ok: [thisNode]
ok: [dww]

TASK [Execute test role] *******************************************************

TASK [testrole : Just debugging] ***********************************************
ok: [dww] => {
"msg": "Hello world!"
}
ok: [thisNode] => {
"msg": "Hello world!"
}

TASK [testrole : Just debugging] ***********************************************
ok: [thisNode] => {
"msg": "Hello world!"
}
ok: [dww] => {
"msg": "Hello world!"
}

PLAY RECAP *********************************************************************
dww : ok=3 changed=0 unreachable=0 failed=0
thisNode : ok=3 changed=0 unreachable=0 failed=0

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION

devel

CONFIGURATION

N/A

OS / ENVIRONMENT

N/A

SUMMARY

include_role+with_items executes once per item per host on each host.

STEPS TO REPRODUCE

x.yml::

---
- hosts: all
gather_facts: no
tasks:
- include_role: name=p
with_items: [1,2]

roles/p/tasks/main.yml::

- command: cat /proc/uptime

EXPECTED RESULTS

I expected cat /proc/uptime to be executed twice on a and twice on b.

ACTUAL RESULTS

It actually executes cat /proc/uptime four times on both hosts.

TASK [p : command] ****************************************************************************************************************************************************************************
changed: [b] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002532", "end": "2016-12-05 20:00:08.080587", "rc": 0, "start": "2016-12-05 20:00:08.078055", "stderr": "", "stdout": "987830.64 3614256.86", "stdout_lines": ["987830.64 3614256.86"], "warnings": []}
changed: [a] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002532", "end": "2016-12-05 20:00:08.080587", "rc": 0, "start": "2016-12-05 20:00:08.078055", "stderr": "", "stdout": "987830.64 3614256.86", "stdout_lines": ["987830.64 3614256.86"], "warnings": []}

TASK [p : command] ****************************************************************************************************************************************************************************
changed: [b] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002069", "end": "2016-12-05 20:00:08.214287", "rc": 0, "start": "2016-12-05 20:00:08.212218", "stderr": "", "stdout": "987830.77 3614257.08", "stdout_lines": ["987830.77 3614257.08"], "warnings": []}
changed: [a] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002710", "end": "2016-12-05 20:00:08.214238", "rc": 0, "start": "2016-12-05 20:00:08.211528", "stderr": "", "stdout": "987830.77 3614257.08", "stdout_lines": ["987830.77 3614257.08"], "warnings": []}

TASK [p : command] ****************************************************************************************************************************************************************************
changed: [a] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002648", "end": "2016-12-05 20:00:08.340613", "rc": 0, "start": "2016-12-05 20:00:08.337965", "stderr": "", "stdout": "987830.90 3614257.30", "stdout_lines": ["987830.90 3614257.30"], "warnings": []}
changed: [b] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002124", "end": "2016-12-05 20:00:08.345231", "rc": 0, "start": "2016-12-05 20:00:08.343107", "stderr": "", "stdout": "987830.91 3614257.30", "stdout_lines": ["987830.91 3614257.30"], "warnings": []}

TASK [p : command] ****************************************************************************************************************************************************************************
changed: [b] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002734", "end": "2016-12-05 20:00:08.475102", "rc": 0, "start": "2016-12-05 20:00:08.472368", "stderr": "", "stdout": "987831.04 3614257.51", "stdout_lines": ["987831.04 3614257.51"], "warnings": []}
changed: [a] => {"changed": true, "cmd": ["cat", "/proc/uptime"], "delta": "0:00:00.002468", "end": "2016-12-05 20:00:08.478968", "rc": 0, "start": "2016-12-05 20:00:08.476500", "stderr": "", "stdout": "987831.04 3614257.52", "stdout_lines": ["987831.04 3614257.52"], "warnings": []}

PLAY RECAP ************************************************************************************************************************************************************************************
a : ok=4 changed=4 unreachable=0 failed=0
b : ok=4 changed=4 unreachable=0 failed=0