Interview Prep/Ansible/Variables, Facts and Precedence

How do registered variables behave across plays and hosts?

IntermediateConceptVariables, Facts and Precedence
Answer

A registered variable is stored per host and stays available for the rest of the playbook run, including later plays on that host. It is not visible to other hosts directly, but you can read it through hostvars['web1']['result'].

It is lost when the run ends (unless set_fact with cacheable). A skipped task still registers a result with skipped: true, so check result is skipped or result.skipped before using result.stdout.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence