Professional Documents
Culture Documents
html)
/ Collections in the Ansible Namespace (../index.html) / Ansible.Windows (index.html)
/ ansible.windows.win_service module – Manage and query Windows services
This is the latest (stable) community version of the Ansible documentation. For Red Hat
customers, see the difference between Ansible community projects and Red Hat
supported products (https://www.ansible.com/compare) or Ansible Automation Platform
Life Cycle (https://access.redhat.com/support/policy/updates/ansible-automation-
platform) for subscriptions.
You might already have this collection installed if you are using the ansible package. It is
not included in ansible-core . To check whether it is installed, run ansible-galaxy
collection list .
Synopsis
Parameters
Notes
See Also
Examples
Return Values
Synopsis
Search this site
M d Wi d i
Manage and query Windows services.
For non-Windows targets, use the ansible.builtin.service
(../builtin/service_module.html#ansible-collections-ansible-builtin-service-module)
module instead.
Parameters
dependencies
list / elements=string
dependency_action
string
Used in conjunction with dependency to either add the dependencies to the existing service
dependencies.
Remove the dependencies to the existing dependencies.
Set the dependencies to only the values in the list replacing the existing dependencies.
Choices:
"add"
"remove"
"set" ← (default)
description
string
desktop_interact
boolean
Choices:
false ← (default)
true
display_name
string
The severity of the error and action token if the service fails to start.
A new service defaults to normal .
critical will log the error and restart the system with the last-known good configuration. If
the startup fails on reboot then the system will fail to operate.
ignore ignores the error.
normal logs the error in the event log but continues.
severe is like critical but a failure on the last-known good configuration reboot startup will
be ignored.
Choices:
"critical"
"ignore"
"normal"
"severe"
failure_actions
list / elements=dictionary
A list of failure actions the service controller should take on each failure of a service.
The service manager will run the actions from first to last defined until the service starts. If
failure_reset_period_sec has been exceeded then the failure actions will restart from the
beginning.
If all actions have been performed the the service manager will repeat the last service defined.
The existing actions will be replaced with the list defined in the task if there is a mismatch with
any of them.
Set to an empty list to delete all failure actions on a service otherwise an omitted or null value
preserves the existing actions on the service.
delay_ms
aliases: delay
any
"none"
"reboot"
"restart"
"run_command"
failure_actions_on_non_crash_failure
boolean
Controls whether failure actions will be performed on non crash failures or not.
Choices:
false
true
failure_command
string
failure_reboot_msg
string
The message to be broadcast to users logged on the host for a reboot failure action.
Set to an empty string to remove the message.
failure_reset_period_sec
aliases: failure_reset_period
any
The time in seconds after which the failure action list resets back to the start of the list if there
are no failures.
To set this value, failure_actions must have at least 1 action present.
Specify '0xFFFFFFFF' to set an infinite reset period.
If true , stopping or restarting a service with dependent services will force the dependent
services to stop or restart also.
If false , stopping or restarting a service with dependent services may fail.
Choices:
false ← (default)
true
load_order_group
string
The name of the load ordering group of which this service is a member.
Specify an empty string to remove the existing load order group of a service.
name
string / required
password
string
path
string
pre_shutdown_timeout_ms
aliases: pre_shutdown_timeout
any
The time in which the service manager waits after sending a preshutdown notification to the
service until it proceeds to continue with the other shutdown actions.
service_type
string
Choices:
"user_own_process"
"user_share_process"
"win32_own_process"
"win32_share_process"
sid_info
string
"none"
"restricted"
"unrestricted"
"auto"
"delayed"
"disabled"
"manual"
state
string
"absent"
"paused"
"started"
"stopped"
"restarted"
update_password
string
When set to always and password is set, the module will always report a change and set the
password.
Set to on_create to only set the password if the module needs to create the service.
If username was specified and the service changed to that username then password will also be
changed if specified.
The current default is on_create but this behaviour may change in the future, it is best to be
explicit here.
Choices:
"always"
"on_create"
Notes
Note
This module historically returning information about the service in its return values.
These should be avoided in favour of the ansible.windows.win_service_info
(win_service_info_module.html#ansible-collections-ansible-windows-win-service-info-
module) module.
Most of the options in this module are non-driver services that you can view in
SCManager. While you can edit driver services, not all functionality may be available.
The user running the module must have the following access rights on the service to
be able to use it with this module - SERVICE_CHANGE_CONFIG ,
SERVICE_ENUMERATE_DEPENDENTS , SERVICE_QUERY_CONFIG , SERVICE_QUERY_STATUS .
Changing the state or removing the service will also require futher rights depending on
what needs to be done.
See Also
See also
ansible.builtin.service (../builtin/service_module.html#ansible-collections-ansible-builtin-
service-module)
Manage services.
community.windows.win_nssm
(../../community/windows/win_nssm_module.html#ansible-collections-community-
windows-win-nssm-module)
Install a service using NSSM.
ansible.windows.win_service_info (win_service_info_module.html#ansible-collections-
ansible-windows-win-service-info-module)
Gather information about Windows services.
ansible.windows.win_user_right (win_user_right_module.html#ansible-collections-
ansible-windows-win-user-right-module) Search this site
Manage Windows User Rights.
- name: Ensure that WinRM is started when the system has settled
ansible.windows.win_service:
name: WinRM
start_mode: delayed
# This is required to be set for non-service accounts that need to run as a service
- name: Grant domain account the SeServiceLogonRight user right
ansible.windows.win_user_right:
name: SeServiceLogonRight
users:
- DOMAIN\User
action: add
- name: Set the log on user to Local System and allow it to interact with the desktop
ansible.windows.win_service:
name: service name
state: restarted
username: SYSTEM
desktop_interact: true
- name: Set only 1 failure action without a repeat of the last action
ansible.windows.win_service:
name: service name
failure_actions:
- type: restart
delay_ms: 5000
- type: none
Return Values
can_pause_and_continue
boolean
depended_by
list / elements=string
description
string
desktop_interact
boolean
display_name
string
exists
boolean
name
string
path
string
state
string
username
string
Authors
Collection links
Communication (index.html#communication-for-ansible-windows)