Issue 1:
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.

I notice that a few changes were made in runner/init.py that may be the cause of the regression.

Here is a sample to reproduce the error:

playbook:

---
- hosts: group1
gather_facts: no

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

- name: fail
delegate_to: "{{ groups.group2 | first }}"
fetch: >
fail_on_missing=no
src=somefile
dest=somefile

inventory:

[group1]
127.0.0.1 ansible_connection=local

[group2]
127.0.0.1 ansible_connection=local

error message:

fatal: [127.0.0.1 -> 127.0.0.1] => 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 }}

Issue 2:
Issue Type:

"Bug Report"

Ansible Version:

1.8.2

Environment:

Ubuntu 12.04

Summary:

Modules using Runner._remote_checksum (like template, copy, etc) are broken when used with delegate_to containing var in it

Steps To Reproduce:

Take following playbook and save as delegat_test.yml:

- hosts: all
gather_facts: no
vars:
d: 127.0.0.1
tasks:
- copy:
dest: /tmp/tmpl
content: lalalala
delegate_to: "{{ d }}"

Then run as following (note that "-c local" doesn't make any difference for the purpose of this ticket):

ansible-playbook -c local -i '127.0.0.1,' delegate_test.yml

Expected Results:

Results from 1.7.2

PLAY [all] ********************************************************************

TASK: [copy ] *****************************************************************
changed: [127.0.0.1 -> 127.0.0.1]

PLAY RECAP ********************************************************************
127.0.0.1 : ok=1 changed=1 unreachable=0 failed=0

Actual Results:

PLAY [all] ********************************************************************

TASK: [copy ] *****************************************************************
fatal: [127.0.0.1 -> 127.0.0.1] => 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