# Ansible seems to have issues resolving nested variables for delegate\_to

**URL:** <https://forum.ansible.com/t/ansible-seems-to-have-issues-resolving-nested-variables-for-delegate-to/37382>\
**Category:** Ansible Developer\
**Created:** [November 23, 2022, 2:12pm UTC](https://forum.ansible.com/t/ansible-seems-to-have-issues-resolving-nested-variables-for-delegate-to/37382 "2022-11-23T14:12:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Richter](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@Marc\_Richter](https://forum.ansible.com/u/Marc_Richter)\
**Post date:** [November 23, 2022, 2:12pm UTC](https://forum.ansible.com/t/ansible-seems-to-have-issues-resolving-nested-variables-for-delegate-to/37382/1 "2022-11-23T14:12:13Z")

</div>

Hi everyone,

to be honest, I filed a bug report [1](https://github.com/ansible/ansible/issues/79450) 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](https://github.com/The-Judge/ansible-delegate-demo) 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:

```auto
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?
