I have two synced LDAP servers (Master / Master configured). I want to call a role on one server and try to connect to the second ldap server to run this role ONLY IF the first server is not reachable for some reason.
The run_once concept seems interesting. Include with run_once, even without ping will make the included tasks to be ran one time only if the host is reachable.
What I thought (but not tested) is having 2 plays in a playbook. The first one checks which server is available and with set_fact defines its hostname. Then I can use this fact to declare the host on the second play.
I am still open to new suggestions so if anyone has a cleaner / better way, I would be glad to hear it.
run_once will fail if it is the first task to attempt to contact an unreachable host, i mentioned the ping as a way to guarantee this is not the case.
If using 2 plays i would suggest using add_host/group_by to update the targets for the 2nd play as set_fact is PER HOST and wont be accessible by the play’s hosts: directive.