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

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

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

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!

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