For everyone else's benefit, let me step back a little and provide some background info.
(A)
Ansible has a directory called "host_vars/" where you can store variables that are host specific
(B)
"hostvars" refers to an datastructure that can be used for getting variables from other hosts.
For instance, if I want the OS family of a server named "
foo.example.com" when accessed from a template about *another* host:
This is usually unneccessary as if you want the variable for your current host it's just
{{ ansible_os_family }}
So the question is not, "how does the code work", but what problem are you trying to solve that you are having trouble with?
(C)
Your question was "some of my plays on hosts need dynamic information from other hosts so I am trying to understand when/which variable in the playbooks become available in hostvars."
If you need to get a "fact" (some information discovered about a remote system that is not explicitly set as a variable, but derived from talking to it), you need to talk to that system in an earlier play.
For instance if the DB servers need the IP addresses of all the webservers, this is common:
- hosts: webservers
tasks: []
- hosts: dbservers
tasks:
- # things go here
Talking to the webservers before will get their fact information.
Variables set otherwise are already availble, and do not require talking to the hosts.
Sometime in 1.5 timeframe, we'll also be implementing a way to store facts from previous runs, so you don't have to talk to nodes within the same play.