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
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
to ansible...@googlegroups.com
Hi,

maybe a little bit ugly but what about a block in combination with
delegate_to and rescue.

http://docs.ansible.com/ansible/playbooks_blocks.html

Regards
Christian
> --
> 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-proje...@googlegroups.com
> <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com
> <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/43a47c99-1e73-4e9b-a349-847c02880038%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/43a47c99-1e73-4e9b-a349-847c02880038%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
toscom - the open source company

Christian Rusa
Breiteneckergasse 32 1230 Wien
Mobil: 0699 10205595 Fax: 01 9249633
www.toscom.at christi...@toscom.at

Brian Coca

unread,
Nov 10, 2016, 4:37:06 PM11/10/16
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
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
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.


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages