# How to persist variables/facts in ansible?

**URL:** <https://forum.ansible.com/t/how-to-persist-variables-facts-in-ansible/19177>\
**Category:** Ansible Project\
**Created:** [September 3, 2015, 11:27am UTC](https://forum.ansible.com/t/how-to-persist-variables-facts-in-ansible/19177 "2015-09-03T11:27:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diwaakartg\_Ganesh](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Diwaakartg\_Ganesh](https://forum.ansible.com/u/Diwaakartg_Ganesh)\
**Post date:** [September 3, 2015, 11:27am UTC](https://forum.ansible.com/t/how-to-persist-variables-facts-in-ansible/19177/1 "2015-09-03T11:27:47Z")

</div>

checking out the documentation, modules like set\_fact and register have scope only for that specific host. There are many purpose of using the variables from one host to another.

Alternatives I can think of:

1. using Command module and echoing the variables to a file. Later, using the variable file using vars section or include.

2. Setting the env variables and then accessing it but this will be difficult.

So what is the solution?

---

<div class="post-metadata">

**Author:** ![Takeshi\_Yaegashi](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@Takeshi\_Yaegashi](https://forum.ansible.com/u/Takeshi_Yaegashi)\
**Post date:** [September 5, 2015, 6:29am UTC](https://forum.ansible.com/t/how-to-persist-variables-facts-in-ansible/19177/2 "2015-09-05T06:29:09Z")

</div>

Hello,

You can use hostvars[hostname] to get facts set by other hosts. play\_hosts array is also useful.

The following playbook collects root’s SSH public keys from all hosts, then distributes keys back to all hosts.

`
