# delegate\_to with target server's context?

**URL:** <https://forum.ansible.com/t/delegate-to-with-target-servers-context/15811>\
**Category:** Ansible Project\
**Created:** [July 30, 2014, 9:22am UTC](https://forum.ansible.com/t/delegate-to-with-target-servers-context/15811 "2014-07-30T09:22:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [July 30, 2014, 9:22am UTC](https://forum.ansible.com/t/delegate-to-with-target-servers-context/15811/1 "2014-07-30T09:22:09Z")

</div>

Hi all  
I need to trigger an action (generating a file using template) on another server during a play run. Naturally I used delegation. However, if I use variables like ansible\_hostname I get the values from the _original_ host. That’s indeed what I would expect on most cases, but is there a way to use the “context” of the target server?

Example playbook:

- hosts: source  
tasks:
- debug: var=ansible\_hostname  
delegate\_to: target

What I get:

TASK: [debug var=ansible\_hostname] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“ansible\_hostname”: “source”  
}

What I want to get:

TASK: [debug var=ansible\_hostname] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“ansible\_hostname”: “target”  
}

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 30, 2014, 12:07pm UTC](https://forum.ansible.com/t/delegate-to-with-target-servers-context/15811/2 "2014-07-30T12:07:36Z")

</div>

There’s no magic variable for this presently.

If you’d like to work on it, or submit a feature idea ticket, a variable like “delegated\_host” could be added.
