<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.7.2</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">CentOS 6.4</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Variable substitution occur only once when delegate_to using with serial.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">hosts</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="host1  copy_from=host9
host2  copy_from=host8
host3  copy_from=host7"><pre class="notranslate"><code class="notranslate">host1  copy_from=host9
host2  copy_from=host8
host3  copy_from=host7
</code></pre></div>
<p dir="auto">playbook.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: all
  serial: 1
  tasks:
   - debug: msg={{ copy_from }}
     delegate_to: &quot;{{ copy_from }}&quot;"><pre class="notranslate"><code class="notranslate">
---
- hosts: all
  serial: 1
  tasks:
   - debug: msg={{ copy_from }}
     delegate_to: "{{ copy_from }}"
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host3 -&gt; host7] =&gt; {
    &quot;msg&quot;: &quot;host7&quot;
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host2 -&gt; host8] =&gt; {
    &quot;msg&quot;: &quot;host8&quot;
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host1 -&gt; host9] =&gt; {
    &quot;msg&quot;: &quot;host9&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host3 -&gt; host7] =&gt; {
    "msg": "host7"
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host2 -&gt; host8] =&gt; {
    "msg": "host8"
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host1 -&gt; host9] =&gt; {
    "msg": "host9"
}
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host3 -&gt; host9] =&gt; {
    &quot;msg&quot;: &quot;host9&quot;
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host2 -&gt; host9] =&gt; {
    &quot;msg&quot;: &quot;host8&quot;
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host1 -&gt; host9] =&gt; {
    &quot;msg&quot;: &quot;host7&quot;
}"><pre class="notranslate"><code class="notranslate">TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host3 -&gt; host9] =&gt; {
    "msg": "host9"
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host2 -&gt; host9] =&gt; {
    "msg": "host8"
}

TASK: [debug msg={{ copy_from }}] *********************************************
ok: [host1 -&gt; host9] =&gt; {
    "msg": "host7"
}
</code></pre></div>
<h5 dir="auto">Workaround:</h5>
<p dir="auto">playbook.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: all
  serial: 1
  tasks:
   - debug: msg={{ copy_from }}
     delegate_to: &quot;{{ item }}&quot;
     with_items:
       - &quot;{{ copy_from }}&quot;"><pre class="notranslate"><code class="notranslate">
---
- hosts: all
  serial: 1
  tasks:
   - debug: msg={{ copy_from }}
     delegate_to: "{{ item }}"
     with_items:
       - "{{ copy_from }}"
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">all versions</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">There is a bug in the templating code of <code class="notranslate">delegate_to:</code> in that, it only happens once per runner proces fork, instead of for every host.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Test inventory and playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ for n in `seq 0 20`; do echo host$n &gt;&gt; hosts ; done
$ cat test.yml

---
- hosts: all
  gather_facts: false
  connection: local
  tasks:
    - command: sleep 1
      delegate_to: '{{ inventory_hostname }}'"><pre class="notranslate"><code class="notranslate">$ for n in `seq 0 20`; do echo host$n &gt;&gt; hosts ; done
$ cat test.yml

---
- hosts: all
  gather_facts: false
  connection: local
  tasks:
    - command: sleep 1
      delegate_to: '{{ inventory_hostname }}'
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto"><code class="notranslate">ansible-playbook -i hosts test.yml -f 1</code> (or whatever value for fork)</p>
<p dir="auto">TASK: [command sleep 1] *******************************************************<br>
changed: [host1 -&gt; host1]<br>
changed: [host0 -&gt; host0]<br>
changed: [host2 -&gt; host2]<br>
changed: [host4 -&gt; host4]<br>
changed: [host8 -&gt; host8]<br>
changed: [host3 -&gt; host3]<br>
changed: [host6 -&gt; host6]<br>
changed: [host9 -&gt; host9]<br>
changed: [host5 -&gt; host5]<br>
changed: [host14 -&gt; host14]<br>
changed: [host16 -&gt; host16]<br>
changed: [host15 -&gt; host15]<br>
changed: [host10 -&gt; host10]<br>
changed: [host13 -&gt; host13]<br>
changed: [host11 -&gt; host11]<br>
changed: [host18 -&gt; host18]<br>
changed: [host17 -&gt; host17]<br>
changed: [host20 -&gt; host20]<br>
changed: [host19 -&gt; host19]<br>
changed: [host7 -&gt; host7]<br>
changed: [host12 -&gt; host12]</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto"><code class="notranslate">ansible-playbook -i hosts test.yml -f 1</code><br>
TASK: [command sleep 1] *******************************************************<br>
changed: [host0 -&gt; host0]<br>
changed: [host1 -&gt; host0]<br>
changed: [host2 -&gt; host0]<br>
changed: [host3 -&gt; host0]<br>
changed: [host4 -&gt; host0]<br>
changed: [host5 -&gt; host0]<br>
changed: [host6 -&gt; host0]<br>
changed: [host7 -&gt; host0]<br>
changed: [host8 -&gt; host0]<br>
...</p>
<p dir="auto"><code class="notranslate">ansible-playbook -i hosts test.yml -f 2</code><br>
TASK: [command sleep 1] *******************************************************<br>
changed: [host1 -&gt; host1]<br>
changed: [host0 -&gt; host0]<br>
changed: [host3 -&gt; host0]<br>
changed: [host2 -&gt; host1]<br>
changed: [host5 -&gt; host1]<br>
changed: [host4 -&gt; host0]<br>
changed: [host6 -&gt; host1]<br>
changed: [host7 -&gt; host0]<br>
changed: [host9 -&gt; host0]<br>
...</p>
<p dir="auto"><code class="notranslate">ansible-playbook -i hosts test.yml -f 3</code><br>
TASK: [command sleep 1] *******************************************************<br>
changed: [host2 -&gt; host2]<br>
changed: [host1 -&gt; host1]<br>
changed: [host0 -&gt; host0]<br>
changed: [host3 -&gt; host2]<br>
changed: [host4 -&gt; host1]<br>
changed: [host5 -&gt; host0]<br>
changed: [host6 -&gt; host2]<br>
changed: [host7 -&gt; host1]<br>
...</p>
<p dir="auto">The same effect can also be seen by varying the <code class="notranslate">serial:</code> option in the play.</p>