# how far away can a \`register:\` be referenced?

**URL:** <https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583>\
**Category:** Ansible Project\
**Created:** [September 30, 2013, 8:20pm UTC](https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583 "2013-09-30T20:20:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skylar\_Saveland](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@Skylar\_Saveland](https://forum.ansible.com/u/Skylar_Saveland)\
**Post date:** [September 30, 2013, 8:20pm UTC](https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583/1 "2013-09-30T20:20:02Z")

</div>

If I have a task

- name: foo  
…  
register: foo\_result

can I interrogate that result in a `when:` in pretty much any task or handler in my playbook that comes after or is the usage confined to the play I am in (or confined in some other way)?

I’d like to have a play upfront which runs a role on all hosts. I’m hoping that for each host, I will get foo\_result for use in subsequent plays which invoke various roles.

- hosts: all  
roles:
- common
- hosts: some  
roles:
- some
- hosts: more  
roles:
- more

So, if I register foo\_result in a task in roles/common/main.yml, can I do a `when: foo_result.changed` in roles `some` and `more`?

Can I use `foo_result.changed` in subsequent plays in handlers, post\_tasks, etc, too?

Note that `foo_result` can be different for each hosts. I’m hoping that this will all work as I want, that for each host I can use foo\_result everywhere and that hosts’ specific value of foo\_result will be available. Sorry if this is obvious or if I missed the answer in the docs somewhere.

Thanks,  
Skylar

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 30, 2013, 8:21pm UTC](https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583/2 "2013-09-30T20:21:17Z")

</div>

As long as it’s in the same run, once you register a variable it should be available for the rest of the run.

---

<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:** [September 30, 2013, 8:21pm UTC](https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583/3 "2013-09-30T20:21:23Z")

</div>

A registered variable becomes a fact, so it’s a available in hostvars and accessible even outside of the play.

It does not – yet – survive between playbook runs – that’s something we’re going to be working on (caching facts) as an option.

And yes, it’s host specific like that too!

---

<div class="post-metadata">

**Author:** ![Skylar\_Saveland](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@Skylar\_Saveland](https://forum.ansible.com/u/Skylar_Saveland)\
**Post date:** [September 30, 2013, 8:34pm UTC](https://forum.ansible.com/t/how-far-away-can-a-register-be-referenced/13583/4 "2013-09-30T20:34:13Z")

</div>

Brilliant! How great is that? I didn’t want to start a big refactor on a figment of my hope. Thanks, guys.
