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

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 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?

- 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.

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
  failed_when: false

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

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://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