# Is there a way to check if a service is already enabled on a linux machine?

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241>\
**Category:** Ansible Project\
**Created:** [August 2, 2018, 7:11pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241 "2018-08-02T19:11:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 2, 2018, 7:11pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/1 "2018-08-02T19:11:51Z")

</div>

I don’t see a way to do it with service\_facts, do I have to use shell magic?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 2, 2018, 10:03pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/2 "2018-08-02T22:03:50Z")

</div>

You can use the appropriate service module:

- service: name=myservice enabled=yes  
&nbsp;&nbsp;check\_mode: true  
&nbsp;&nbsp;register: isit

- fail: msg=its not enabled  
&nbsp;&nbsp;when: isit is changed

---

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 3, 2018, 12:52pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/3 "2018-08-03T12:52:31Z")

</div>

Awesome! Thanks!

YK

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [August 3, 2018, 1:14pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/4 "2018-08-03T13:14:15Z")

</div>

> Awesome! Thanks!

As an option, you can also use the service\_facts module to inspect  
service state: [https://docs.ansible.com/ansible/latest/modules/service\_facts\_module.html#service-facts-module](https://docs.ansible.com/ansible/latest/modules/service_facts_module.html#service-facts-module)

-AdamM

---

<div class="post-metadata">

**Author:** ![Pavel\_Cahyna](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@Pavel\_Cahyna](https://forum.ansible.com/u/Pavel_Cahyna)\
**Post date:** [August 3, 2018, 1:24pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/5 "2018-08-03T13:24:31Z")

</div>

> \>  
> \> Awesome! Thanks!
> 
> As an option, you can also use the service\_facts module to inspect  
> service state: [https://docs.ansible.com/ansible/latest/modules/service\_facts\_module.html#service-facts-module](https://docs.ansible.com/ansible/latest/modules/service_facts_module.html#service-facts-module)

You can not, because the facts do not tell whether a service is enabled  
or disabled.

P.

---

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 3, 2018, 1:29pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/6 "2018-08-03T13:29:46Z")

</div>

I was actually thinking of trying to change that, but I’m short on time. Should I log a ticket or is that out of scope for the module?

I was also thinking about making it possible for service\_facts to operate only on a single service, in order to save time on data collection. Same question - should I log something for that or is it out of scope?

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [August 3, 2018, 1:43pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/7 "2018-08-03T13:43:19Z")

</div>

> I was actually thinking of trying to change that, but I'm short on time. Should I log a ticket or is that out of scope for the module?
> 
> I was also thinking about making it possible for service\_facts to operate only on a single service, in order to save time on data collection. Same question - should I log something for that or is it out of scope?

Please file an issue ticket, that's something the module should  
probably be providing. I actually thought it did (which I'm apparently  
mistaken on).

-AdamM

---

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 3, 2018, 1:54pm UTC](https://forum.ansible.com/t/is-there-a-way-to-check-if-a-service-is-already-enabled-on-a-linux-machine/28241/8 "2018-08-03T13:54:54Z")

</div>

done, for both:  
[https://github.com/ansible/ansible/issues/43641](https://github.com/ansible/ansible/issues/43641)

[https://github.com/ansible/ansible/issues/43642](https://github.com/ansible/ansible/issues/43642)
