Uri monitoring is working in ansible

- name: "url monitor and restart if its down"
hosts: servers
gather_facts: no
tasks:
- name: "Check 8101 instances is running on {{ inventory_hostname }}"
uri:
url: "http://{{inventory_hostname}}:8101/health"
register: result_01
- name: status code
debug:
var: result_01.status
- name: "Restart instance on {{ inventory_hostname }} "
shell: restart.sh
when: result_01.status != 200

When the url is down, restart task is not executing. getting below error.

FAILED! => {“ansible_facts”: {“discovered_interpreter_python”: “/usr/bin/python”}, “changed”: false, “contentand not [200]: Request failed: <urlopen error [Errno 111] Connection refused>”, “redirected”: false, “status”: -1,

Could someone help on this

Hello @paragi.ravi ,

Could you clarify how you did write the value of inventory_hostname ? also please run the playbook again after adding -vvv argument and provide me with the output as it seems that you are trying to access the wrong URL.

Thanks,
KodeKloud Support