# Pass Ansible variable to remote host

**URL:** <https://forum.ansible.com/t/pass-ansible-variable-to-remote-host/25307>\
**Category:** Ansible Project\
**Created:** [August 22, 2017, 1:13pm UTC](https://forum.ansible.com/t/pass-ansible-variable-to-remote-host/25307 "2017-08-22T13:13:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mladen\_Stankovic](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Mladen\_Stankovic](https://forum.ansible.com/u/Mladen_Stankovic)\
**Post date:** [August 22, 2017, 1:13pm UTC](https://forum.ansible.com/t/pass-ansible-variable-to-remote-host/25307/1 "2017-08-22T13:13:28Z")

</div>

Hi,

I am trying to pass a variable defined in Ansible host to a remote host, using lookup plugin **native hashi\_vault** , but play returns an error that variable is not defined.  
The same variable returns expected value on the localhost but not on the remote host. Folowing command was used: _{{ hostvars[‘localhost’][‘vault\_pass’] }}_ but without no luck.

Can you please advise the best way to obtain variable from Ansible lookup plugin, and use it on the remote host? I am aware that lookup plugin executes only on Ansible host.

BR,  
Mladen

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 25, 2017, 8:42pm UTC](https://forum.ansible.com/t/pass-ansible-variable-to-remote-host/25307/2 "2017-08-25T20:42:46Z")

</div>

The lookup plugin will run on the ansible controller but the result will be  
per host.

Let's say we have this playbook

- hosts: all  
&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;motd: "{{ lookup('file', '/etc/motd') }}"

All the host in the inventory will now have a variable called motd that  
contains the content of the /etc/motd on the Ansible controller.

---

<div class="post-metadata">

**Author:** ![Mladen\_Stankovic](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Mladen\_Stankovic](https://forum.ansible.com/u/Mladen_Stankovic)\
**Post date:** [August 28, 2017, 12:46pm UTC](https://forum.ansible.com/t/pass-ansible-variable-to-remote-host/25307/3 "2017-08-28T12:46:30Z")

</div>

Hi,

thank you very match for your comment. I have created new inventory file with one server and accomplished what I want.

BR,  
Mladen
