In code the difference is mostly that hostvars is a 'cache' object
that internally implements most (but not all, it seems) the methods of
a dictionary. The default cache is an actual in memory dictionary but
the object still acts as an intermediary.
There is probably a way to make it behave exactly the same in this
case, but I would need to look into it deeper.
serge@cyberlab:~/tmp$ ansible all -i localhost, -c local -m debug -a var=hostvars[inventory_hostname]
localhost | success >> {
"hostvars[inventory_hostname]": {
"group_names": [],
"inventory_hostname": "localhost",
"inventory_hostname_short": "localhost"
}
}
serge@cyberlab:~/tmp$ ansible all -i localhost, -c local -m debug -a var=hostvars
localhost | success >> {
"hostvars": {
"group_names": [],
"inventory_hostname": "localhost",
"inventory_hostname_short": "localhost"
}
}