<p dir="auto">Seems that 1.8.2 has a breaking change related to delegate_to.   In earlier releases, it was possible to use an expression as the value of delegate_to.  Now an error is thrown by certain modules including fetch.</p>
<p dir="auto">I notice that a few changes were made in runner/<strong>init</strong>.py that may be the cause of the regression.</p>
<p dir="auto">Here is a sample to reproduce the error:</p>
<p dir="auto">playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: group1
  gather_facts: no

  tasks:
  - name: pass
    delegate_to: &quot;{{ groups.group2 | first }}&quot;
    shell: whoami

  - name: fail
    delegate_to: &quot;{{ groups.group2 | first }}&quot;
    fetch: &gt;
      fail_on_missing=no
      src=somefile
      dest=somefile"><pre class="notranslate"><code class="notranslate">
---
- hosts: group1
  gather_facts: no

  tasks:
  - name: pass
    delegate_to: "{{ groups.group2 | first }}"
    shell: whoami

  - name: fail
    delegate_to: "{{ groups.group2 | first }}"
    fetch: &gt;
      fail_on_missing=no
      src=somefile
      dest=somefile
</code></pre></div>
<p dir="auto">inventory:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[group1]
127.0.0.1 ansible_connection=local

[group2]
127.0.0.1 ansible_connection=local"><pre class="notranslate"><code class="notranslate">[group1]
127.0.0.1 ansible_connection=local

[group2]
127.0.0.1 ansible_connection=local
</code></pre></div>
<p dir="auto">error message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [127.0.0.1 -&gt; 127.0.0.1] =&gt; Traceback (most recent call last):
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 792, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 1025, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/action_plugins/fetch.py&quot;, line 77, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp, source, inject)
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 1231, in _remote_checksum
    python_interp = inject['hostvars'][inject['delegate_to']].get('ansible_python_interpreter', 'python')
  File &quot;/usr/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 103, in __getitem__
    result = self.inventory.get_variables(host, vault_password=self.vault_password).copy()
  File &quot;/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py&quot;, line 442, in get_variables
    raise Exception(&quot;host not found: %s&quot; % hostname)
Exception: host not found: {{ groups.group2 | first }}"><pre class="notranslate"><code class="notranslate">fatal: [127.0.0.1 -&gt; 127.0.0.1] =&gt; Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 792, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1025, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/usr/lib/python2.7/site-packages/ansible/runner/action_plugins/fetch.py", line 77, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp, source, inject)
  File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1231, in _remote_checksum
    python_interp = inject['hostvars'][inject['delegate_to']].get('ansible_python_interpreter', 'python')
  File "/usr/lib/python2.7/site-packages/ansible/runner/__init__.py", line 103, in __getitem__
    result = self.inventory.get_variables(host, vault_password=self.vault_password).copy()
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 442, in get_variables
    raise Exception("host not found: %s" % hostname)
Exception: host not found: {{ groups.group2 | first }}
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">"Bug Report"</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.8.2</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu 12.04</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Modules using <code class="notranslate">Runner._remote_checksum</code> (like template, copy, etc)  are broken when used with delegate_to  containing var in it</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Take following playbook and save as <em>delegat_test.yml</em>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: all
  gather_facts: no
  vars:
    d: 127.0.0.1
  tasks:
    - copy:
        dest: /tmp/tmpl
        content: lalalala
      delegate_to: &quot;{{ d }}&quot;"><pre class="notranslate"><code class="notranslate">- hosts: all
  gather_facts: no
  vars:
    d: 127.0.0.1
  tasks:
    - copy:
        dest: /tmp/tmpl
        content: lalalala
      delegate_to: "{{ d }}"
</code></pre></div>
<p dir="auto">Then run as following (note that "-c local" doesn't make any difference for the purpose of this ticket):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -c local -i '127.0.0.1,' delegate_test.yml"><pre class="notranslate"><code class="notranslate">ansible-playbook -c local -i '127.0.0.1,' delegate_test.yml
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Results from 1.7.2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [all] ******************************************************************** 

TASK: [copy ] ***************************************************************** 
changed: [127.0.0.1 -&gt; 127.0.0.1]

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=1    changed=1    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">PLAY [all] ******************************************************************** 

TASK: [copy ] ***************************************************************** 
changed: [127.0.0.1 -&gt; 127.0.0.1]

PLAY RECAP ******************************************************************** 
127.0.0.1                  : ok=1    changed=1    unreachable=0    failed=0   
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [all] ******************************************************************** 

TASK: [copy ] ***************************************************************** 
fatal: [127.0.0.1 -&gt; 127.0.0.1] =&gt; Traceback (most recent call last):
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 792, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 1025, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/action_plugins/copy.py&quot;, line 181, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp_path, dest_file, inject)
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 1231, in _remote_checksum
    python_interp = inject['hostvars'][inject['delegate_to']].get('ansible_python_interpreter', 'python')
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py&quot;, line 103, in __getitem__
    result = self.inventory.get_variables(host, vault_password=self.vault_password).copy()
  File &quot;/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/inventory/__init__.py&quot;, line 442, in get_variables
    raise Exception(&quot;host not found: %s&quot; % hostname)
Exception: host not found: {{ d }}


FATAL: all hosts have already failed -- aborting"><pre class="notranslate"><code class="notranslate">PLAY [all] ******************************************************************** 

TASK: [copy ] ***************************************************************** 
fatal: [127.0.0.1 -&gt; 127.0.0.1] =&gt; Traceback (most recent call last):
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py", line 590, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py", line 792, in _executor_internal
    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1025, in _executor_internal_inner
    result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/action_plugins/copy.py", line 181, in run
    remote_checksum = self.runner._remote_checksum(conn, tmp_path, dest_file, inject)
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py", line 1231, in _remote_checksum
    python_interp = inject['hostvars'][inject['delegate_to']].get('ansible_python_interpreter', 'python')
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/runner/__init__.py", line 103, in __getitem__
    result = self.inventory.get_variables(host, vault_password=self.vault_password).copy()
  File "/home/rossmohax/repos/vdna/ansible/.pyenv/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 442, in get_variables
    raise Exception("host not found: %s" % hostname)
Exception: host not found: {{ d }}


FATAL: all hosts have already failed -- aborting
</code></pre></div>