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

244 views
Skip to first unread message

Kishor Ramanan

unread,
Jan 12, 2017, 3:05:37 PM1/12/17
to Ansible Project
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
 Main PID: 815 (dockerd)
   Memory: 65.3M
   CGroup: /system.slice/docker.service
           ├─  815 /usr/bin/dockerd


Johannes Kastl

unread,
Jan 13, 2017, 4:06:32 AM1/13/17
to ansible...@googlegroups.com
On 12.01.17 20:39 Kishor Ramanan wrote:
> 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
> Main PID: 815 (dockerd) Memory: 65.3M CGroup:
> /system.slice/docker.service ├─ 815 /usr/bin/dockerd

If I understand the check_mode description right, you could do
something like this:

- service:
name: "docker"
state: "started"
check_mode: yes
register: docker_service_status

- debug: msg="Docker is running"
when: 'docker_service_status.change == false'

https://docs.ansible.com/ansible/playbooks_checkmode.html

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages