How do i store/use information retrieved from running a playbook task later in another playbook task?
I tried dumping the information in json format from the first playbook/task to a file. But then how do i read/pass this information to the new playbook task as input?
But let’s say i need to save information from a task on all remote hosts in a local file (or files), how do i do it? So that in the next yml file, i can load the local file for all remote hosts.
It's possible to store all "hostvars". For example with this template
$ cat my_hostvars.json.j2
my_hostvars_all:
{% for my_host in ansible_play_hosts_all %}
{{ my_host }}:
{{ hostvars[my_host]|to_nice_json }}
{% endfor %}
the playbook below stores "hostvars" of all hosts in the dictionary
"my_hostvars_all" and put it into the file
"{{ inventory_dir }}/my_hostvars.json" at localhost