# Trying to use previous task output to new task to modify one file, But it is throwing error variable not defined

**URL:** <https://forum.ansible.com/t/trying-to-use-previous-task-output-to-new-task-to-modify-one-file-but-it-is-throwing-error-variable-not-defined/24281>\
**Category:** Ansible Project\
**Created:** [April 21, 2017, 11:36am UTC](https://forum.ansible.com/t/trying-to-use-previous-task-output-to-new-task-to-modify-one-file-but-it-is-throwing-error-variable-not-defined/24281 "2017-04-21T11:36:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudhanshu\_Sharma](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@Sudhanshu\_Sharma](https://forum.ansible.com/u/Sudhanshu_Sharma)\
**Post date:** [April 21, 2017, 11:36am UTC](https://forum.ansible.com/t/trying-to-use-previous-task-output-to-new-task-to-modify-one-file-but-it-is-throwing-error-variable-not-defined/24281/1 "2017-04-21T11:36:57Z")

</div>

Hi,

I am trying to use previous task output to new task to modify one file, But it is throwing error variable not defined -

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 21, 2017, 8:02pm UTC](https://forum.ansible.com/t/trying-to-use-previous-task-output-to-new-task-to-modify-one-file-but-it-is-throwing-error-variable-not-defined/24281/2 "2017-04-21T20:02:07Z")

</div>

x only exists for host4, in the context of host3 it does not, you need to do:

{{hostvars['host4']['x']['stdout']}}

---

<div class="post-metadata">

**Author:** ![Sudhanshu\_Sharma](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@Sudhanshu\_Sharma](https://forum.ansible.com/u/Sudhanshu_Sharma)\
**Post date:** [April 22, 2017, 2:05pm UTC](https://forum.ansible.com/t/trying-to-use-previous-task-output-to-new-task-to-modify-one-file-but-it-is-throwing-error-variable-not-defined/24281/3 "2017-04-22T14:05:06Z")

</div>

Thanks Brian,

Its working.

as I am using Ansible version 2.2 so I used " instead of ’ -

{{hostvars[“host4”][“x”][“stdout”]}}

Thanks once again 🙂

Br//Sudhanshu
