# Only execute task then certain URL is NOT reachable

**URL:** <https://forum.ansible.com/t/only-execute-task-then-certain-url-is-not-reachable/22432>\
**Category:** Ansible Project\
**Created:** [August 31, 2016, 2:10pm UTC](https://forum.ansible.com/t/only-execute-task-then-certain-url-is-not-reachable/22432 "2016-08-31T14:10:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guenther.grill](https://avatars.discourse-cdn.com/v4/letter/g/e56c9b/32.png) [@guenther.grill](https://forum.ansible.com/u/guenther.grill)\
**Post date:** [August 31, 2016, 2:10pm UTC](https://forum.ansible.com/t/only-execute-task-then-certain-url-is-not-reachable/22432/1 "2016-08-31T14:10:47Z")

</div>

Hi,

I have a setup with Apache Mesos and Marathon.  
I also deploy a Elasticsearch with JSON to the Mesos Cluster via Ansible.  
But this should only be done, when a certain endpont [http://mesos](http://mesos)…:8080/v2/apps/elasticserach  
is NOT reachable. That indicates, that the module is already (or isn’t) installed.

How can I do that in my main.yml?

regards  
guenther

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 2, 2016, 11:50am UTC](https://forum.ansible.com/t/only-execute-task-then-certain-url-is-not-reachable/22432/2 "2016-09-02T11:50:14Z")

</div>

The principle is like this.

Use the uri[1] module to check the url and register[2] the output in a variable.

Use when[3] to check the variable to determine if the task should run or not.

[1] [https://docs.ansible.com/ansible/uri\_module.html](https://docs.ansible.com/ansible/uri_module.html)  
[2] [https://docs.ansible.com/ansible/playbooks\_variables.html#registered-variables](https://docs.ansible.com/ansible/playbooks_variables.html#registered-variables)  
[3] [https://docs.ansible.com/ansible/playbooks\_conditionals.html](https://docs.ansible.com/ansible/playbooks_conditionals.html)
