# playbook saving variables for later

**URL:** <https://forum.ansible.com/t/playbook-saving-variables-for-later/13147>\
**Category:** Ansible Project\
**Created:** [July 17, 2013, 11:37pm UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147 "2013-07-17T23:37:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boris2](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@Boris2](https://forum.ansible.com/u/Boris2)\
**Post date:** [July 17, 2013, 11:37pm UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/1 "2013-07-17T23:37:16Z")

</div>

Can I save a variable in one playbook, so it can be used by another one at a later time?  
For example: playbook running cloudformation server provisioning task outputs some info that later needs to be used by playbook configuring software on those servers.

I guess I could just use lineinfile on a vars file to update a variable there, but may be there is a better way?

Thanks,  
-Boris

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 18, 2013, 1:06am UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/2 "2013-07-18T01:06:10Z")

</div>

I have an open ticket to cache these (optionally) between runs.

Right now, you cannot.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 18, 2013, 1:06am UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/3 "2013-07-18T01:06:35Z")

</div>

If you have one play firing after the other from the same playbook, you are of course fine.

---

<div class="post-metadata">

**Author:** ![josh2](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@josh2](https://forum.ansible.com/u/josh2)\
**Post date:** [October 9, 2013, 6:27am UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/4 "2013-10-09T06:27:30Z")

</div>

Any update on retaining CloudFormation outputs?

I’m working very intently on making a multi-az multi-tier h/a-minded multi-VPC CloudFormation framework, using [cfndsl](https://github.com/howech/cfndsl) syntax, deployed strictly with Ansible playbooks. (or a custom module, if it comes to that)

Rather than using natively nested templates which require to be on S3 hosting, and due to the tiny limits placed on CloudFormation (10 output values, 51,200 bytes per template), I’m looking to execute (idempotently-possible) interlocking CloudFormation templates which pass outputs as parameters to other templates.

cfndsl provides the mechanism for doing for each loops to generate subnets, routes, route tables, etc. for each tier. At the end of this, I’ll be building a 10-tier 3-zone h/a VPC for application deployment plus a 2 or 3 tier, 3-zone h/a VPC for “universe” management (Ansible will live there).

The goal is to do something like OpsWorks with Ansible, but with cfndsl and multi-tier VPC’s in mind. For VPC’s an abstraction of “tier” is what I think most people would really like. OpsWorks uses “layers” for this, but they are just barely VPC aware.

Thanks,  
Joshua

---

<div class="post-metadata">

**Author:** ![Sergey\_Dobrovolskiy](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sergey\_Dobrovolskiy](https://forum.ansible.com/u/Sergey_Dobrovolskiy)\
**Post date:** [January 7, 2015, 2:14pm UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/5 "2015-01-07T14:14:57Z")

</div>

Hi are there any updates on this topic?

My use case is the following:  
I’m provisioning Redis server on EC2, after it’s done, I’m running ec2\_facts module to get the private IP.  
Later in the infrastructure provisioning I want to be able to use that IP.

Thanks,  
Sergey

---

<div class="post-metadata">

**Author:** ![Sergey\_Dobrovolskiy](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sergey\_Dobrovolskiy](https://forum.ansible.com/u/Sergey_Dobrovolskiy)\
**Post date:** [January 7, 2015, 2:27pm UTC](https://forum.ansible.com/t/playbook-saving-variables-for-later/13147/6 "2015-01-07T14:27:07Z")

</div>

Never mind I found an answer:

tasks:

- name: echo redis ip  
debug: msg=“redis ip {{ hostvars[groups[‘tag\_role\_redis’][0]][‘ec2\_private\_ip\_address’] }}”
