<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<ul dir="auto">
<li>play</li>
<li>role</li>
<li>loop</li>
<li>with_items</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ansible 2.2.2.0<br>
config file =<br>
configured module search path = Default w/o overrides</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">None</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ansile OS: debian 9</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">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</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">ansible-playbook test.yml</p>
<p dir="auto">test.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plays$ cat test.yml
---
- name: Test
  hosts: all
  gather_facts: no

  tasks:

    - name: Enter role
      include_role:
          name: sib
      vars:
          foo: &quot;{{ item }}&quot;
      with_items:
          - bar"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<p dir="auto">sib/tasks/main.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plays$ cat roles/sib/tasks/main.yml 
---

- debug:
    var: foo"><pre class="notranslate"><code class="notranslate">plays$ cat roles/sib/tasks/main.yml 
---

- debug:
    var: foo
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml
 
PLAY [Test] ********************************************************************

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

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}"><pre class="notranslate"><code class="notranslate">plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml
 
PLAY [Test] ********************************************************************

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

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    "foo": "bar"
}
ok: [fe2] =&gt; {
    "foo": "bar"
}
ok: [be1] =&gt; {
    "foo": "bar"
}
ok: [be2] =&gt; {
    "foo": "bar"
}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml
 
PLAY [Test] ********************************************************************

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

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}

TASK [sib : debug] *************************************************************
ok: [be1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [fe2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be1] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}
ok: [be2] =&gt; {
    &quot;foo&quot;: &quot;bar&quot;
}

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   "><pre class="notranslate"><code class="notranslate">plays$ ansible-playbook -i ~/dev/project/base/ansible/hosts test.yml
 
PLAY [Test] ********************************************************************

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

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

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

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

TASK [sib : debug] *************************************************************
ok: [fe1] =&gt; {
    "foo": "bar"
}
ok: [fe2] =&gt; {
    "foo": "bar"
}
ok: [be1] =&gt; {
    "foo": "bar"
}
ok: [be2] =&gt; {
    "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   
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="devel"><pre class="notranslate"><code class="notranslate">devel
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">include_role+with_items executes once per item per host <strong>on each host</strong>.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">x.yml::</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---
- hosts: all
  gather_facts: no
  tasks:
    - include_role: name=p
      with_items: [1,2]"><pre class="notranslate"><code class="notranslate">---
- hosts: all
  gather_facts: no
  tasks:
    - include_role: name=p
      with_items: [1,2]
</code></pre></div>
<p dir="auto">roles/p/tasks/main.yml::</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- command: cat /proc/uptime"><pre class="notranslate"><code class="notranslate">- command: cat /proc/uptime
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">I expected <code class="notranslate">cat /proc/uptime</code> to be executed twice on a and twice on b.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">It actually executes <code class="notranslate">cat /proc/uptime</code> <strong>four times</strong> on both hosts.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [p : command] ****************************************************************************************************************************************************************************
changed: [b] =&gt; {&quot;changed&quot;: true, &quot;cmd&quot;: [&quot;cat&quot;, &quot;/proc/uptime&quot;], &quot;delta&quot;: &quot;0:00:00.002532&quot;, &quot;end&quot;: &quot;2016-12-05 20:00:08.080587&quot;, &quot;rc&quot;: 0, &quot;start&quot;: &quot;2016-12-05 20:00:08.078055&quot;, &quot;stderr&quot;: &quot;&quot;, &quot;stdout&quot;: &quot;987830.64 3614256.86&quot;, &quot;stdout_lines&quot;: [&quot;987830.64 3614256.86&quot;], &quot;warnings&quot;: []}
changed: [a] =&gt; {&quot;changed&quot;: true, &quot;cmd&quot;: [&quot;cat&quot;, &quot;/proc/uptime&quot;], &quot;delta&quot;: &quot;0:00:00.002532&quot;, &quot;end&quot;: &quot;2016-12-05 20:00:08.080587&quot;, &quot;rc&quot;: 0, &quot;start&quot;: &quot;2016-12-05 20:00:08.078055&quot;, &quot;stderr&quot;: &quot;&quot;, &quot;stdout&quot;: &quot;987830.64 3614256.86&quot;, &quot;stdout_lines&quot;: [&quot;987830.64 3614256.86&quot;], &quot;warnings&quot;: []}

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

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

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

PLAY RECAP ************************************************************************************************************************************************************************************
a                          : ok=4    changed=4    unreachable=0    failed=0   
b                          : ok=4    changed=4    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">TASK [p : command] ****************************************************************************************************************************************************************************
changed: [b] =&gt; {"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] =&gt; {"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] =&gt; {"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] =&gt; {"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] =&gt; {"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] =&gt; {"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] =&gt; {"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] =&gt; {"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   
</code></pre></div>