- 1 year ago
Ansible : how to set recovery options in Windows services
In Ansible, you can use the win_service
module to manage Windows services, including setting recovery options. The win_service
module provides various parameters to configure recovery options for a service. Here's an example playbook that demonstrates how to set recovery options for a Windows service:
yaml- name: Configure recovery options for a Windows service
hosts: windows
tasks:
- name: Set recovery options for MyService
win_service:
name: MyService
recovery_enabled: yes
recovery_actions:
- reboot
- restart_service
reset_fail_count: yes
restart_delay: 600
restart_service_delay: 0
failure_command: 'cmd /c echo Service failure occurred!'
In the above example, the win_service
module is used to configure the recovery options for a service named MyService
. The recovery options specified include enabling recovery (recovery_enabled: yes
), specifying recovery actions (recovery_actions
), resetting the failure count (reset_fail_count: yes
), specifying restart delay (restart_delay
), specifying restart service delay (restart_service_delay
), and specifying a failure command (failure_command
).
Adjust the parameters and values according to your requirements. You can refer to the win_service
module documentation for more details on the available options and their usage.
Note: Make sure you have appropriate privileges to manage services on the target Windows hosts.