replace or lineinfile or ?

For a replication project i have to dynamic create an .sql for execute with mariadb.
i have two hosts (A and B) in my host variables, both with name, ip and ID.

i think about create a local file, copy it to the destination hosts and then ?
i need to put the ip address from Server A in the file for Server B.
And the Adress from Server B in the file for Server A.

Does anyone has an idea how to do this quickly?

I think this line of discussion is best suited for the ansible-project
list as that's more focused on users of Ansible aiming to solve real
world problems and share solutions, but this list is meant for
discussion of developing Ansible itself.

Thank you,
-AdamM