# Variables not consumed from delegated host

**URL:** <https://forum.ansible.com/t/variables-not-consumed-from-delegated-host/40621>\
**Category:** Get Help\
**Tags:** ansible-core\
**Created:** [February 25, 2025, 6:41pm UTC](https://forum.ansible.com/t/variables-not-consumed-from-delegated-host/40621 "2025-02-25T18:41:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [February 26, 2025, 12:32pm UTC](https://forum.ansible.com/t/variables-not-consumed-from-delegated-host/40621/3 "2025-02-26T12:32:44Z")

</div>

Digged a bit deeper and this is actually partially true.

When task executor [resolves connection options](https://github.com/ansible/ansible/blob/59d9737788d63ea4e17b74d3c3ca1a0cf03f89ba/lib/ansible/executor/task_executor.py#L620) it templates them using delegated variables (`cvars` and `templar` both contain delegated variables)

Few lines below, [original variables are restored](https://github.com/ansible/ansible/blob/59d9737788d63ea4e17b74d3c3ca1a0cf03f89ba/lib/ansible/executor/task_executor.py#L621-L624) and it will only update connection variables that are not set , due to check in [ConnectionBase.update\_vars()](https://github.com/ansible/ansible/blob/59d9737788d63ea4e17b74d3c3ca1a0cf03f89ba/lib/ansible/plugins/connection/ __init__.py#L256-L258). These variables are listed in [COMMON\_CONNECTION\_VARS](https://github.com/ansible/ansible/blob/a0495fc31497798a7a833ba7406a9729e1528dd8/lib/ansible/constants.py#L201-L203)

So given following inventory:

```auto
db ansible_host=127.0.0.1 ansible_port=2201 ansible_user='vagrant' ansible_ssh_private_key_file='/home/kristian/projects/ansible-playground/.vagrant/machines/db/virtualbox/private_key'
webserver-1 ansible_host=127.0.0.1 ansible_port=2222 ansible_user='vagrant' ansible_ssh_private_key_file='/home/kristian/projects/ansible-playground/.vagrant/machines/webserver-1/virtualbox/private_key'
webserver-2 ansible_host=127.0.0.1 ansible_port=2200 ansible_user='vagrant' ansible_ssh_private_key_file='/home/kristian/projects/ansible-playground/.vagrant/machines/webserver-2/virtualbox/private_key'

```

- `ansible_port` will remain as-is, since it’s already defined
- `ansible_private_key_file` gets set from delegated host, since it’s set as `ansible_ssh_private_key_file` alias in the inventory.

Will see a bit later if i can come up with some concise description of this to update the docs.

---

_[View the full topic](https://forum.ansible.com/t/variables-not-consumed-from-delegated-host/40621)._
