# Setting a variable in one playbook and using that in another

**URL:** <https://forum.ansible.com/t/setting-a-variable-in-one-playbook-and-using-that-in-another/34339>\
**Category:** Ansible Project\
**Created:** [December 15, 2020, 4:54pm UTC](https://forum.ansible.com/t/setting-a-variable-in-one-playbook-and-using-that-in-another/34339 "2020-12-15T16:54:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshay\_Kumar](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Akshay\_Kumar](https://forum.ansible.com/u/Akshay_Kumar)\
**Post date:** [December 15, 2020, 4:54pm UTC](https://forum.ansible.com/t/setting-a-variable-in-one-playbook-and-using-that-in-another/34339/1 "2020-12-15T16:54:35Z")

</div>

Hi Everyone,

Hope all are well .

I have a small query where in i want to know if i can set a variable in one playbook and use that in another playbook.

For eg  
Playbook1 : setting a var with output of shell  
set\_fact:  
var1: test

Playbook2

- debug:  
msg: “{{ var1 }}”

Note : i found one way that i can write these two playbooks and import both using one main playbook , that seems to perform the scenario(still need to test this though :-))

Other than this if anyone has had this scenario before or can provide some insight on this , please do share.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [December 15, 2020, 5:27pm UTC](https://forum.ansible.com/t/setting-a-variable-in-one-playbook-and-using-that-in-another/34339/2 "2020-12-15T17:27:13Z")

</div>

When you need to persist a variable between playbooks, you can use a  
dummy host to tie the variable to:  
[https://stackoverflow.com/a/47811099](https://stackoverflow.com/a/47811099)

---

<div class="post-metadata">

**Author:** ![Akshay\_Kumar](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Akshay\_Kumar](https://forum.ansible.com/u/Akshay_Kumar)\
**Post date:** [December 16, 2020, 1:31pm UTC](https://forum.ansible.com/t/setting-a-variable-in-one-playbook-and-using-that-in-another/34339/3 "2020-12-16T13:31:33Z")

</div>

Thanks a lot D.Visser , appreciate it 🙂
