Hi friends, I am new ansible user and need help with playbook: 1. first task ch . . .

Deep R Gill:
Hi friends, I am new ansible user and need help with playbook:

  1. first task checks the status of service and register the result
  2. second task will log the status in a file if service is down. result.stdout.find(‘inactive’) != -1
name: check status of a service and email if it's up/down
hosts: test-node01
tasks:
- command: sudo systemctl status apache2
  register: result
- name: Log service status
  shell: echo "service is down" > /home/cdeepak/os_service_status.txt
  when: result.stdout.find('inactive') != -1

Please help, thank you :pray:

Mohamed Ayman:
Just add ignore_errors: true to the first task

- command: sudo systemctl status nginx
ignore_errors: true
register: result

Deep R Gill:
Thank you @Mohamed Ayman that worked.