# Variables between playbooks

**URL:** <https://forum.ansible.com/t/variables-between-playbooks/25213>\
**Category:** Ansible Project\
**Created:** [August 9, 2017, 8:56pm UTC](https://forum.ansible.com/t/variables-between-playbooks/25213 "2017-08-09T20:56:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marta.albecka1](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@marta.albecka1](https://forum.ansible.com/u/marta.albecka1)\
**Post date:** [August 9, 2017, 8:56pm UTC](https://forum.ansible.com/t/variables-between-playbooks/25213/1 "2017-08-09T20:56:58Z")

</div>

Hi!  
I have some problem and I can’t figure out the answear to it. I’m relatively new to Ansible so I’m still learning. I have to separate playbooks and I want to set a variable value in one, and use it in the other. So for example in playbook 1 I want to start ec2 instance and I want to safe its instance\_id and in the next playbook run some time after that first I want to delete this instance so I want to get the instance\_id value from the variable. Is this possible, and if so how? If someone knows the answear please provide some simple example, because I have found some ideas, but nothing seems to work. And if the first problem could be solved, would it be possible to save this variable in the first playbook with parameterized variable name?  
Marta

---

<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 10, 2017, 5:34pm UTC](https://forum.ansible.com/t/variables-between-playbooks/25213/2 "2017-08-10T17:34:32Z")

</div>

It's not possible to share variables between playbooks, you can share between play in the same playbook.

What you could do is store the values in a file that you read in playbook number two.

---

<div class="post-metadata">

**Author:** ![Pa\_S](https://avatars.discourse-cdn.com/v4/letter/p/a9a28c/32.png) [@Pa\_S](https://forum.ansible.com/u/Pa_S)\
**Post date:** [August 10, 2017, 6:22pm UTC](https://forum.ansible.com/t/variables-between-playbooks/25213/3 "2017-08-10T18:22:26Z")

</div>

Well, aside from a thread on vars\_files I just posted, you can use facts that seem to span imports of playbooks. see the set\_facts documentation.

You can also set variables in inventory files

---

<div class="post-metadata">

**Author:** ![marta.albecka1](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@marta.albecka1](https://forum.ansible.com/u/marta.albecka1)\
**Post date:** [August 11, 2017, 3:22pm UTC](https://forum.ansible.com/t/variables-between-playbooks/25213/4 "2017-08-11T15:22:49Z")

</div>

Thanks I guess I will put it into a new file.

W dniu czwartek, 10 sierpnia 2017 19:35:04 UTC+2 użytkownik Kai Stian Olstad napisał:
