# How to check status of service running on a remote host via Ansible

**URL:** <https://forum.ansible.com/t/how-to-check-status-of-service-running-on-a-remote-host-via-ansible/23444>\
**Category:** Ansible Project\
**Tags:** rhel\
**Created:** [January 12, 2017, 7:39pm UTC](https://forum.ansible.com/t/how-to-check-status-of-service-running-on-a-remote-host-via-ansible/23444 "2017-01-12T19:39:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kishor\_Ramanan](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Kishor\_Ramanan](https://forum.ansible.com/u/Kishor_Ramanan)\
**Post date:** [January 12, 2017, 7:39pm UTC](https://forum.ansible.com/t/how-to-check-status-of-service-running-on-a-remote-host-via-ansible/23444/1 "2017-01-12T19:39:36Z")

</div>

I am in need of a ansbile play to check the status of a service in CENTOS 7 / RHEL

_Expected output:_

● docker.service - Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)  
Active: active (running) since Tue 2016-11-22 12:24:02 EST; 1 months 20 days ago  
Docs: [https://docs.docker.com](https://docs.docker.com)  
Main PID: 815 (dockerd)  
Memory: 65.3M  
CGroup: /system.slice/docker.service  
├─ 815 /usr/bin/dockerd

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 13, 2017, 9:06am UTC](https://forum.ansible.com/t/how-to-check-status-of-service-running-on-a-remote-host-via-ansible/23444/2 "2017-01-13T09:06:21Z")

</div>

If I understand the check\_mode description right, you could do  
something like this:

- service:  
&nbsp;&nbsp;&nbsp;&nbsp;name: "docker"  
&nbsp;&nbsp;&nbsp;&nbsp;state: "started"  
&nbsp;&nbsp;check\_mode: yes  
&nbsp;&nbsp;register: docker\_service\_status

- debug: msg="Docker is running"  
&nbsp;&nbsp;when: 'docker\_service\_status.change == false'

[https://docs.ansible.com/ansible/playbooks\_checkmode.html](https://docs.ansible.com/ansible/playbooks_checkmode.html)

Johannes
