mail module with when condition

21 views
Skip to first unread message

Milan Patel

unread,
Jul 5, 2022, 4:51:19 PM7/5/22
to Ansible Project
---
- name: This playbook is for Testing Disk Space
  hosts: proxy
  become: yes
  become_method: sudo
  serial: 1
  any_errors_fatal: true
  ignore_errors: yes
  gather_facts: yes
  vars:
          ansible_paython_interpreter: /usr/bin/python
  tasks:


       - name: report the status code
         shell: pgrep -x httpd >/dev/null && echo "active" || echo "inactive"
         register: httpd_active


       - name: check_value_httpd
         debug:
                    msg: "{{ 'httpd is inactive' if httpd_active.stdout=='inactive' else 'service is active' }}"
         register: one

       - name: send mail
         mail:
                 host: xxx.xxx.xxx.xxx
                 port: 25
                 subject: Report for httpd status of system
                 body: Server has httpd service stoped
                 from: xxx.xxx.xxx
                 to: milan patel <milan...@xyz.ca>
                 charset: us-ascii
         when: httpd_active=='inactive'


*****************************

I am trying to check weather httpd service is running or not and if its not running then send an email to me. 
But its just skipping during the process . can some one help to archive this task of mine. is their any other way to do this ? or what is the mistake in my code.
Reply all
Reply to author
Forward
0 new messages