ansible send an email with "OK" status if url is accessible.

Hi,

I have written the ansible playbook to check the url, but I need an email just with “OK” status if the response is 200.

Can you please help me with this?

Thanks.

https://docs.ansible.com/ansible/latest/collections/community/general/mail_module.html

Hi,

Thanks for the reply.

This is my playbook. Here I want to print just “OK” if the status code is 200.

  • hosts: “{{ hosts }}”
    vars_prompt:
  • name: “hosts”
    prompt: “Please enter the hosts details”
    private: no
  • name: “port”
    prompt: “Please enter the port”
    private: no

tasks:

  • name: check the url http://{{ hosts }}:{{ port }}/test
    uri: url: “http://{{ hosts }}:{{ port }}/test”
    follow_redirects: none
    method: GET
    register: _result
    until: _result.status == 200

  • name: Health check for url
    mail:
    host: ‘localhost’
    port:25