Via Ansible-Playbook I would like to check the existence (running) of a service first and then stop the service such as mongod.
Here is the code for stoping service:
- name: stop
service:
name: mongod
state: stopped
But if you run the above script for second time, then it gives you an error that the service is not running.
How can I check the status before running this script? How to ensure that the service is running and then stopping it.
I don't want to use neither "shell" or "command" options in the playbook, I want to use ansible modules.
Solutions at : How to get service status by Ansible? were using shell or command