# how to use dynamic variable set in one play as an input to a task in another play

**URL:** <https://forum.ansible.com/t/how-to-use-dynamic-variable-set-in-one-play-as-an-input-to-a-task-in-another-play/18956>\
**Category:** Ansible Project\
**Created:** [August 5, 2015, 9:24pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-variable-set-in-one-play-as-an-input-to-a-task-in-another-play/18956 "2015-08-05T21:24:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_Allen](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Kathy\_Allen](https://forum.ansible.com/u/Kathy_Allen)\
**Post date:** [August 5, 2015, 9:24pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-variable-set-in-one-play-as-an-input-to-a-task-in-another-play/18956/1 "2015-08-05T21:24:39Z")

</div>

Hiya.

In my playbook, I have two plays: the first is to be run on the control host, the second is run on a set of remote app hosts. What I want to do is have a variable determined by a task in the first play be used as a shell script argument for a task in the second play. I don’t know how to do this. Can anyone help? Is this possible?

Here’s a simplification of how these are called in my ansible deployment orchestration playbook. The json determined by a tool on the control host in `common/test_prep.yml needs to be used as the input parameter to a tool which is called inside of ``common/test_client_check.yml on each client 'myhosts'.`

`  
$ cat testplaybook.yml

---

<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:** [August 5, 2015, 9:47pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-variable-set-in-one-play-as-an-input-to-a-task-in-another-play/18956/2 "2015-08-05T21:47:09Z")

</div>

the data you want is in:

hostvars['localhost']['json\_as\_input\_for\_next\_play']

---

<div class="post-metadata">

**Author:** ![Kathy\_Allen](https://avatars.discourse-cdn.com/v4/letter/k/839c29/32.png) [@Kathy\_Allen](https://forum.ansible.com/u/Kathy_Allen)\
**Post date:** [August 5, 2015, 10:34pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-variable-set-in-one-play-as-an-input-to-a-task-in-another-play/18956/3 "2015-08-05T22:34:20Z")

</div>

Yep. Thank you! A coworker pointed out a similar post: [https://groups.google.com/forum/#!searchin/ansible-project/felix/ansible-project/C51U547IXwY/2IyoNqCZpTQJ](https://groups.google.com/forum/#!searchin/ansible-project/felix/ansible-project/C51U547IXwY/2IyoNqCZpTQJ). Sorry I didn’t catch that one before I posted my question.

I feared that hostvars dict created in localhost task might not be available to the remote host. But that’s not the case, it is available and it worked.

kallen
