# Pass output variable of one role as an input to another role

**URL:** <https://forum.ansible.com/t/pass-output-variable-of-one-role-as-an-input-to-another-role/27054>\
**Category:** Ansible Project\
**Created:** [March 20, 2018, 3:41pm UTC](https://forum.ansible.com/t/pass-output-variable-of-one-role-as-an-input-to-another-role/27054 "2018-03-20T15:41:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ukesh\_Kumar\_Vasudeva](https://avatars.discourse-cdn.com/v4/letter/u/90ced4/32.png) [@Ukesh\_Kumar\_Vasudeva](https://forum.ansible.com/u/Ukesh_Kumar_Vasudeva)\
**Post date:** [March 20, 2018, 3:41pm UTC](https://forum.ansible.com/t/pass-output-variable-of-one-role-as-an-input-to-another-role/27054/1 "2018-03-20T15:41:41Z")

</div>

Hi,

I am having the below ansible script.

While executing the script, I am getting error in the role ‘install-packages’. The error is,

“msg”: "The task includes an option with an undefined variable. The error was: {{ ip }}: ‘ip’ is undefined.

It is looking for ‘ip’ variable inside the role ‘install-packages’,

Please provide your feedback…

---

<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:** [March 22, 2018, 8:33pm UTC](https://forum.ansible.com/t/pass-output-variable-of-one-role-as-an-input-to-another-role/27054/2 "2018-03-22T20:33:03Z")

</div>

You are setting the variable on host local not on host new\_vms so the variable ip doesn't exist there.  
To access the variable you need to use hostvars and specify which host you like the get the ip variable from.

&nbsp;&nbsp;&nbsp;{{ hostvars['local'].ip }}
