While executing my playbook, I cancelled the playbook execution when win_service task for stopping a service was in play. When I re-ran the playbook, it failed to stop the windows service. The windows service status was changed from “running” to “stoppending” after the first playbook execution. The status of the service is displayed as “Stopping” on the windows machine.
The code snippet from my playbook is as below:-
`
-
hosts: all
gather_facts: no
tasks: -
name: Service ‘XYZ’ exists?
win_service:
name: XYZ
register: XYZ_service -
name: Stop ‘XYZ’ service
win_service:
name: XYZ
state: stopped
when: XYZ_service.exists
`
Is this an expected behavior?
Please provide a solution this problem.