ansible / ansible.builtin / v2.3.0.0-1 / module / win_service Manages Windows services | "added in version" 1.7 of ansible.builtin" Authors: Chris Hoffman (@chrishoffman) stableinterface | supported by coreansible.builtin.win_service (v2.3.0.0-1) — module
pip
Install with pip install ansible==2.3.0.0.post1
Manages Windows services
- name: Restart a service win_service: name: spooler state: restarted
- name: Set service startup mode to auto and ensure it is started win_service: name: spooler start_mode: auto state: started
# a new service will also default to the following values: # - username: LocalSystem # - state: stopped # - start_mode: auto - name: create a new service win_service: name: service name path: C:\temp\test.exe
- name: create a new service with extra details win_service: name: service name path: C:\temp\test.exe display_name: Service Name description: A test service description
- name: remove a service win_service: name: service name state: absent
- name: check if a service is installed win_service: name: service name register: service_info
- name: set the log on user to a domain account win_service: name: service name state: restarted username: DOMAIN\User password: Password
- name: set the log on user to a local account win_service: name: service name state: restarted username: .\Administrator password: Password
- name: set the log on user to Local System win_service: name: service name state: restarted username: LocalSystem password: ""
- name: set the log on user to Local System and allow it to interact with the desktop win_service: name: service name state: restarted username: LocalSystem password: "" desktop_interact: True
- name: set the log on user to Network Service win_service: name: service name state: restarted username: NT AUTHORITY\NetworkService password: ""
- name: set the log on user to Local Service win_service: name: service name state: restarted username: NT AUTHORITY\LocalService password: ""
- name: set dependencies to ones only in the list win_service: name: service name dependencies: ['service1', 'service2']
- name: add dependencies to existing dependencies win_service: name: service name dependencies: ['service1', 'service2'] dependency_action: add
- name: remove dependencies from existing dependencies win_service: name: service name dependencies: ['service1', 'service2'] dependency_action: remove
name: description: - Name of the service required: true path: description: - The path to the executable to set for the service. version_added: '2.3' version_added_collection: ansible.builtin state: choices: - started - stopped - restarted - absent description: - C(started)/C(stopped)/C(absent) are idempotent actions that will not run commands unless necessary. - C(restarted) will always bounce the service. - C(absent) added in Ansible 2.3 password: description: - The password to set the service to start as. - This and the C(username) argument must be supplied together. - If specifying LocalSystem, NetworkService or LocalService this field must be an empty string and not null. version_added: '2.3' version_added_collection: ansible.builtin username: description: - The username to set the service to start as. - This and the C(password) argument must be supplied together. version_added: '2.3' version_added_collection: ansible.builtin start_mode: choices: - auto - manual - disabled - delayed description: - Set the startup type for the service. - C(delayed) added in Ansible 2.3 description: description: - The description to set for the service. version_added: '2.3' version_added_collection: ansible.builtin dependencies: description: - A list of service dependencies to set for this particular service. - This should be a list of service names and not the display name of the service. - This works by C(dependency_action) to either add/remove or set the services in this list. version_added: '2.3' version_added_collection: ansible.builtin display_name: description: - The display name to set for the service. version_added: '2.3' version_added_collection: ansible.builtin desktop_interact: default: false description: - Whether to allow the service user to interact with the desktop. - This should only be set to true when using the LocalSystem username. version_added: '2.3' version_added_collection: ansible.builtin dependency_action: choices: - set - add - remove default: set description: - Used in conjunction with C(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. version_added: '2.3' version_added_collection: ansible.builtin force_dependent_services: default: false description: - 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. version_added: '2.3' version_added_collection: ansible.builtin
depended_by: description: A list of dependencies this service relies on returned: success and service exists sample: false type: List dependencies: description: A list of dependencies the service relies on returned: success and service exists sample: false type: List description: description: the path to the executable of the service returned: success and service exists sample: Manages communication between system components. type: string desktop_interact: description: Whether the current user is allowed to interact with the desktop returned: success and service exists sample: false type: boolean display_name: description: the display name of the installed service returned: success and service exists sample: CoreMessaging type: string exists: description: whether the service exists or not returned: success sample: true type: boolean name: description: the service name or id of the service returned: success and service exists sample: CoreMessagingRegistrar type: string path: description: null returned: success and service exists sample: C:\Windows\system32\svchost.exe -k LocalServiceNoNetwork type: string start_mode: description: the startup type of the service returned: success and service exists sample: manual type: string status: description: the current running status of the service returned: success and service exists sample: stopped type: string username: description: the username that runs the service returned: success and service exists sample: LocalSystem type: string