# How to access hostvar of different host in replace module

**URL:** <https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308>\
**Category:** Ansible Developer\
**Created:** [December 20, 2018, 12:12am UTC](https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308 "2018-12-20T00:12:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dineshkumar\_Ramasamy](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dineshkumar\_Ramasamy](https://forum.ansible.com/u/Dineshkumar_Ramasamy)\
**Post date:** [December 20, 2018, 12:12am UTC](https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308/1 "2018-12-20T00:12:02Z")

</div>

Hi,

I’m trying to access hostvar in replace module but I could not access the same.

hosts:

---

<div class="post-metadata">

**Author:** ![Ludovic\_Petetin](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Ludovic\_Petetin](https://forum.ansible.com/u/Ludovic_Petetin)\
**Post date:** [December 20, 2018, 5:44am UTC](https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308/2 "2018-12-20T05:44:04Z")

</div>

Hi,

the variable syntax seems to be wrong.

Could you please try to replace:  
replace: ‘private\_ip: {{ hostvars.[serverFqdn][‘host\_ip’] }}’

by :  
replace: “private\_ip: {{ hostvars[serverFqdn][‘host\_ip’] }}”

Thanks,

---

<div class="post-metadata">

**Author:** ![Dineshkumar\_Ramasamy](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dineshkumar\_Ramasamy](https://forum.ansible.com/u/Dineshkumar_Ramasamy)\
**Post date:** [December 20, 2018, 3:33pm UTC](https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308/3 "2018-12-20T15:33:34Z")

</div>

Hi Petetin,

Thanks for your response.

The proposed code fails to get the actual value from hostvar; instead, the code itself placed in the ‘path’.

**Result:**

_cat /tmp/test\_params.yaml_  
_private\_ip: hostvars[‘[server1.com](http://server1.com)’].host\_ip_

Looks like we need some other way to eval ‘_hostvars[‘[server1.com](http://server1.com)’].host\_ip_’.

I did try _replace: “{{ “private\_ip: {{ hostvars[serverFqdn][‘host\_ip’] }}”}}”_ but no luck.

Regards,  
Dinesh

---

<div class="post-metadata">

**Author:** ![Dineshkumar\_Ramasamy](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dineshkumar\_Ramasamy](https://forum.ansible.com/u/Dineshkumar_Ramasamy)\
**Post date:** [December 20, 2018, 3:57pm UTC](https://forum.ansible.com/t/how-to-access-hostvar-of-different-host-in-replace-module/29308/4 "2018-12-20T15:57:11Z")

</div>

Thanks a lot, Petetin.

My bad; the variable format suggested by you works fine. Please ignore my previous email.

Regards,  
Dinesh
