Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

play

role

loop

with_items

ANSIBLE VERSION

ansible 2.2.2.0

config file =

configured module search path = Default w/o overrides

CONFIGURATION

None

OS / ENVIRONMENT

Ansile OS: debian 9

SUMMARY

When using calling a role from a play with a with_items loop for a var, ansible is making a double loop on each hosts

STEPS TO REPRODUCE

ansible-playbook test.yml

test.yml:

plays$ cat test.yml
---
- name: Test
hosts: all
gather_facts: no

tasks:

- name: Enter role
include_role:
name: sib
vars:
foo: "{{ item }}"
with_items:
- bar

sib/tasks/main.yml

plays$ cat roles/sib/tasks/main.yml
---

- debug:
var: foo

EXPECTED RESULTS

plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml

PLAY [Test] ********************************************************************

TASK [Enter role] **************************************************************

TASK [sib : debug] *************************************************************
ok: [fe1] => {
"foo": "bar"
}
ok: [fe2] => {
"foo": "bar"
}
ok: [be1] => {
"foo": "bar"
}
ok: [be2] => {
"foo": "bar"
}

ACTUAL RESULTS

plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml

PLAY [Test] ********************************************************************

TASK [Enter role] **************************************************************

TASK [sib : debug] *************************************************************
ok: [fe1] => {
"foo": "bar"
}
ok: [fe2] => {
"foo": "bar"
}
ok: [be1] => {
"foo": "bar"
}
ok: [be2] => {
"foo": "bar"
}

TASK [sib : debug] *************************************************************
ok: [be1] => {
"foo": "bar"
}
ok: [fe2] => {
"foo": "bar"
}
ok: [fe1] => {
"foo": "bar"
}
ok: [be2] => {
"foo": "bar"
}

TASK [sib : debug] *************************************************************
ok: [fe1] => {
"foo": "bar"
}
ok: [fe2] => {
"foo": "bar"
}
ok: [be1] => {
"foo": "bar"
}
ok: [be2] => {
"foo": "bar"
}

TASK [sib : debug] *************************************************************
ok: [fe1] => {
"foo": "bar"
}
ok: [fe2] => {
"foo": "bar"
}
ok: [be1] => {
"foo": "bar"
}
ok: [be2] => {
"foo": "bar"
}

PLAY RECAP *********************************************************************
be1 : ok=4 changed=0 unreachable=0 failed=0
be2 : ok=4 changed=0 unreachable=0 failed=0
fe1 : ok=4 changed=0 unreachable=0 failed=0
fe2 : ok=4 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