# service module state=disabled vs. removed query

**URL:** <https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906>\
**Category:** Ansible Project\
**Created:** [November 14, 2013, 1:04pm UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906 "2013-11-14T13:04:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 14, 2013, 1:04pm UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906/1 "2013-11-14T13:04:04Z")

</div>

Hi,

I am trying to write some compliance tasksto check if insecure configurations are presents and remedy them, one issue i am facing with the below snippet is that it fails as service is not installed, should there be another state=removed? or shouldn’t the state disabled in the case of software removed return success as in reality the service is not installed so it is disabled in a way

- name: disable insecure services “rsh, rlogin, and rexec”

service: name = {{ item }} state=disabled

with\_items:

- rsh

- rlogin

- rexec

regards

Walid

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 14, 2013, 3:41pm UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906/2 "2013-11-14T15:41:03Z")

</div>

to remove them i would use the appropriate package module, the service module does and should not install/uninstall.

Make sure you remove AFTER you disable as some systems will not stop the service on removal and might leave it running and any init scripts (or alternatives) will have been removed.

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 14, 2013, 11:53pm UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906/3 "2013-11-14T23:53:16Z")

</div>

Hi Brian,

First as you said I would like to make sure if the service exists and make sure its disabled and remove it or just disable it notify its existence, however the service module will fail if they are not installed. i can not just “ignore\_errors” as what if it ignores a service that can not be disabled.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 15, 2013, 12:57am UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906/4 "2013-11-15T00:57:45Z")

</div>

Right, I would use the “stat” module in combination with register, to check for the init script, and if present disable it (using “when”)

– Michael

---

<div class="post-metadata">

**Author:** ![Walid](https://avatars.discourse-cdn.com/v4/letter/w/ea5d25/32.png) [@Walid](https://forum.ansible.com/u/Walid)\
**Post date:** [November 15, 2013, 2:23am UTC](https://forum.ansible.com/t/service-module-state-disabled-vs-removed-query/13906/5 "2013-11-15T02:23:49Z")

</div>

Thanks Michael, that should work fine in our case
