Re: [ansible-project] replace or lineinfile ?

2018-08-10 Thread Kai Stian Olstad

On 10.08.2018 11:09, Henrik Schuetze wrote:
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?


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

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cd7d9f30c878a8ac129cd5a49b23b301%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] replace or lineinfile ?

2018-08-10 Thread Henrik Schuetze
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?


greetings
Henrik

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fdfebc71-44f8-4059-88ad-5675c6c06233%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.