# Can I set a variable on one host and use them on other hosts?

**URL:** <https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742>\
**Category:** Ansible Project\
**Created:** [July 23, 2014, 1:51pm UTC](https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742 "2014-07-23T13:51:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@Benjamin\_Bauer](https://forum.ansible.com/u/Benjamin_Bauer)\
**Post date:** [July 23, 2014, 1:51pm UTC](https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742/1 "2014-07-23T13:51:24Z")

</div>

I’m writing a playbook to restore the latest backup of my DB on all my Database servers. This is done in two main steps:

1. figure out which backup is the latest (once)
2. download that file to all DB servers
3. …and run the restore

While step 2 and 3 are straight forward, my problem is to **acquire the correct filename once and share it among all DB hosts**.

I was trying something like this for testing, but I cant access `last_mongo` on the DB hosts.

`

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@Benjamin\_Bauer](https://forum.ansible.com/u/Benjamin_Bauer)\
**Post date:** [July 23, 2014, 2:05pm UTC](https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742/2 "2014-07-23T14:05:25Z")

</div>

Update:

I figured it out:

`

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [July 23, 2014, 5:18pm UTC](https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742/3 "2014-07-23T17:18:35Z")

</div>

Yes, use hostvars.localhost.lmongo.stdout

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@Benjamin\_Bauer](https://forum.ansible.com/u/Benjamin_Bauer)\
**Post date:** [July 25, 2014, 12:30pm UTC](https://forum.ansible.com/t/can-i-set-a-variable-on-one-host-and-use-them-on-other-hosts/15742/4 "2014-07-25T12:30:54Z")

</div>

Thanks for the good adivce!
