How to persist variables/facts in ansible?

checking out the documentation, modules like set_fact and register have scope only for that specific host. There are many purpose of using the variables from one host to another.

Alternatives I can think of:

  1. using Command module and echoing the variables to a file. Later, using the variable file using vars section or include.

  2. Setting the env variables and then accessing it but this will be difficult.

So what is the solution?

Hello,

You can use hostvars[hostname] to get facts set by other hosts. play_hosts array is also useful.

The following playbook collects root’s SSH public keys from all hosts, then distributes keys back to all hosts.

`