There is many ways to do this, it all comes down to your environment.
In any case you should probably use the template module.
If this is a play that only has two hosts A and B, you could use this to
find the other host.
- debug: msg="{{ (ansible_play_hosts | reject('equalto',
inventory_hostname) | list)[0] }}"
And to get the IP from Ansible fact on the other host that would be
- debug: msg="{{ hostvars[(ansible_play_hosts | reject('equalto',
inventory_hostname) | list)[0]].ansible_default_ipv4.address }}"
--
Kai Stian Olstad