# Is possible keep variable beetween roles?

**URL:** <https://forum.ansible.com/t/is-possible-keep-variable-beetween-roles/24821>\
**Category:** Ansible Developer\
**Created:** [June 26, 2017, 8:34am UTC](https://forum.ansible.com/t/is-possible-keep-variable-beetween-roles/24821 "2017-06-26T08:34:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aitor\_Gomez](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Aitor\_Gomez](https://forum.ansible.com/u/Aitor_Gomez)\
**Post date:** [June 26, 2017, 8:34am UTC](https://forum.ansible.com/t/is-possible-keep-variable-beetween-roles/24821/1 "2017-06-26T08:34:39Z")

</div>

this is an example that i want… in this task i set in a pretask the variable INSTALL\_TIME: “{{ ansible\_date\_time }}”  
i whant to use this variable in other role (Check\_logs)

how can i do that?

- name: ‘Deploy’  
hosts: APP  
pre\_tasks:

- set\_fact:  
INSTALL\_TIME: “{{ ansible\_date\_time }}”  
roles:

- role: install\_block

- name: ‘[Global] Check Logs’

hosts: LOG  
become: false  
roles:

- role: check\_logs

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 26, 2017, 4:02pm UTC](https://forum.ansible.com/t/is-possible-keep-variable-beetween-roles/24821/2 "2017-06-26T16:02:26Z")

</div>

That is not between roles as much as 'between plays', the variables  
you use `set_fact` with are set PER HOST which means they DO survive  
across plays.

But, since you target different hosts in the 2nd play you need to use  
`hostvars[\<a host in APP group\>]['INSTALL_TIME']` to access it.
