Ansible seems to have issues resolving nested variables for delegate_to

Hi everyone,

to be honest, I filed a bug report 1 for this prior to addressing the issue here, because I simply overlooked that there is an Ansible Mailing List.
If this leads somewhere, I will update that one.

I have prepared a very small Git Repo 2 with only 23 lines of Ansible code to demonstrate my issue; let me explain it a bit:

Sometimes, I use include_task to re-use code or execute multiple tasks when the when condition matches for specific nodes, only. When I execute tasks with delegate_to and provide the delegation node with a variable (say: variable my_execution_node contains sbsdevcore02 and a task contains delegate_to: "{{ my_execution_node }}"), I receive a very strange error:

TASK [test : debug] ******************************************************************************************************************************************************************************************************************** task path: /Users/mrichter/Desktop/ansible-delegate-demo/roles/test/tasks/sub_task.yml:2 ok: [sbsdevcore01] => { "msg": "my_execution_node: sbsdevcore03" } ok: [sbsdevcore02] => { "msg": "my_execution_node: sbsdevcore03" } ok: [sbsdevcore03] => { "msg": "my_execution_node: sbsdevcore01" } TASK [test : This is my sub-task] ****************************************************************************************************************************************************************************************************** task path: /Users/mrichter/Desktop/ansible-delegate-demo/roles/test/tasks/sub_task.yml:5 fatal: [sbsdevcore01 -> sbsdevcore02]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname inventory_hostname: nodename nor servname provided, or not known", "unreachable": true}

As you can see here by [sbsdevcore01 -> sbsdevcore02], the node sbsdevcore01 delegates a task to the node sbsdevcore02 fine, but that task fails, with a message that looks as if Ansible tries to use the string inventory_hostname to connect to by SSH, instead of the appropriate content of ansible_host fact of the node sbsdevcore02.

Any ideas what I am doing wrong or what might be the issue?