Move on second server only if first server is unreachable
48 views
Skip to first unread message
Mpampis Mpigkonias
unread,
Nov 10, 2016, 8:37:34 AM11/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
Hello people,
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.
Any idea of how this could be done?
Thanks in advance.
Christian Rusa
unread,
Nov 10, 2016, 8:42:22 AM11/10/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
Hi,
maybe a little bit ugly but what about a block in combination with
delegate_to and rescue.
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
use run_once after a ping task.
--
----------
Brian Coca
Mpampis Mpigkonias
unread,
Nov 11, 2016, 9:13:03 AM11/11/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
Thanks for the replies guys.
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.
Cheers.
Brian Coca
unread,
Nov 11, 2016, 11:09:31 AM11/11/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
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.