# 'service' should succeed to stop a service, even if non-existant (and spelling issues)

**URL:** <https://forum.ansible.com/t/service-should-succeed-to-stop-a-service-even-if-non-existant-and-spelling-issues/26674>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [February 6, 2018, 6:08pm UTC](https://forum.ansible.com/t/service-should-succeed-to-stop-a-service-even-if-non-existant-and-spelling-issues/26674 "2018-02-06T18:08:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![burton](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@burton](https://forum.ansible.com/u/burton)\
**Post date:** [February 6, 2018, 6:08pm UTC](https://forum.ansible.com/t/service-should-succeed-to-stop-a-service-even-if-non-existant-and-spelling-issues/26674/1 "2018-02-06T18:08:31Z")

</div>

Right now if you stop a service which isn’t installed you get an error.

```auto
service: name=kube-apiserver state=stopped

```

… if the kube-apiservice service isn’t installed it will just fail.

It shouldn’t fail. It’s ‘stopped’ which is the same as not existing in a way.

I need this for un-installation of software.

I want an idempotent script that stops all the services, removes the packages, and removes the config files.

Right now I can’t do this as ansible isn’t idempotent for some operations.

I reported a bug for this and it was rejected because there could be a spelling error in the name.

Which is somewhat true.

but then what about this?

```auto
- apt: name=kubernetes-server state=absent

```

that will succeed if you have a spelling error in the name.

So let’s be consistent here? Which one is it?

Perhaps we need some more states to resolve this?

Maybe an ‘absent’ on ‘service’ which will ‘stop’ the service? the only problem is that it’s not ‘absent’ at that point.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 6, 2018, 6:21pm UTC](https://forum.ansible.com/t/service-should-succeed-to-stop-a-service-even-if-non-existant-and-spelling-issues/26674/2 "2018-02-06T18:21:41Z")

</div>

> Right now if you stop a service which isn't installed you get an error.
> 
> service: name=kube-apiserver state=stopped
> 
> .. if the kube-apiservice service isn't installed it will just fail.
> 
> It shouldn't fail. It's 'stopped' which is the same as not existing in a  
> way.

I guess you can't stop something that doesn't exist, so in that sense it makes sense.

> I need this for un-installation of software.
> 
> I want an idempotent script that stops all the services, removes the  
> packages, and removes the config files.
> 
> Right now I can't do this as ansible isn't idempotent for some operations.

You have a lot of what to tell Ansible what you expect, one of them is failed\_when.

- service: name=kube-apiserver state=stopped  
&nbsp;&nbsp;failed\_when: false

So yes, you can do it with Ansible right now.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 6, 2018, 6:21pm UTC](https://forum.ansible.com/t/service-should-succeed-to-stop-a-service-even-if-non-existant-and-spelling-issues/26674/3 "2018-02-06T18:21:56Z")

</div>

We have had many discussions about this in the past, and just recently made a decision about it in our core team meeting.

We intend on keeping the current behavior, but to get your expected outcome you should either used `failed_when` or `ignore_errors` to allow that to succeed when the service is missing. In 2.5 you can also make use of the `service_facts` module to use in determining if you need to stop that service.

[https://github.com/ansible/community/issues/291#issuecomment-360274948](https://github.com/ansible/community/issues/291#issuecomment-360274948)

[https://meetbot.fedoraproject.org/teams/ansible\_core\_meeting/ansible\_core\_meeting.2018-01-30-19.00.log.html](https://meetbot.fedoraproject.org/teams/ansible_core_meeting/ansible_core_meeting.2018-01-30-19.00.log.html)

[https://meetbot.fedoraproject.org/teams/ansible\_core\_meeting/ansible\_core\_meeting.2018-01-30-19.00.html](https://meetbot.fedoraproject.org/teams/ansible_core_meeting/ansible_core_meeting.2018-01-30-19.00.html)
