While using ceph-ansible purge-cluster.yml script I ran into this problem. If you run a task like:
- name: stop ceph mdss with systemd
service:
name: ceph-mds@{{ ansible_hostname }}
state: stopped
enabled: no
when: ansible_service_mgr == 'systemd'
when the service was never installed to begin with, the error is:
TASK [stop ceph mdss with systemd] *********************************************
fatal: [ip-172-31-27-179]: FAILED! => {"changed": false, "failed": true, "msg":
"Could not find the requested service ceph-mds@ip-172-31-27-179: cannot disable" }
I thought that Ansible playbooks should ideally be idempotent, so that if you
run them 2 times in a row, it's the same as if you ran them just once.
The service module here is being asked to stop the ceph-mds@foo systemd service,
but if that service does not exist, then by definition it is not running (right?),
so then the idempotent (right) thing to do is to return success, yes?
If so, is there a bug in the ansible service module?
Or is it expected that the playbook will test to see if the service is defined before it tries to stop it?
If the latter, this seems a bit awkward. Software removal
is a common activities in system management and it would be nice to make this as easy as possible
to specify. Typically you have to shut down a service before you remove the software
that provides it, so it's inconvenient to have to test for the software package's installation before you
shut down the service.