summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/windows/win_service_info.py
blob: a3fbf49d879a52d9860fa53d6b240da630ab8bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2020, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = r'''
---
module: win_service_info
version_added: '2.10'
short_description: Gather information about Windows services
description:
- Gather information about all or a specific installed Windows service(s).
options:
  name:
    description:
    - If specified, this is used to match the C(name) or C(display_name) of the Windows service to get the info for.
    - Can be a wildcard to match multiple services but the wildcard will only be matched on the C(name) of the service
      and not C(display_name).
    - If omitted then all services will returned.
    type: str
seealso:
- module: win_service
author:
- Jordan Borean (@jborean93)
'''

EXAMPLES = r'''
- name: Get info for all installed services
  win_service_info:
  register: service_info

- name: Get info for a single service
  win_service_info:
    name: WinRM
  register: service_info

- name: Get info for a service using its display name
  win_service_info:
    name: Windows Remote Management (WS-Management)

- name: Find all services that start with 'win'
  win_service_info:
    name: win*
'''

RETURN = r'''
exists:
  description: Whether any services were found based on the criteria specified.
  returned: always
  type: bool
  sample: true
services:
  description:
  - A list of service(s) that were found based on the criteria.
  - Will be an empty list if no services were found.
  returned: always
  type: list
  elements: dict
  contains:
    checkpoint:
      description:
      - A check-point value that the service increments periodically to report its progress.
      type: int
      sample: 0
    controls_accepted:
      description:
      - A list of controls that the service can accept.
      - Common controls are C(stop), C(pause_continue), C(shutdown).
      type: list
      elements: str
      sample: ['stop', 'shutdown']
    dependencies:
      description:
      - A list of services by their C(name) that this service is dependent on.
      type: list
      elements: str
      sample: ['HTTP', 'RPCSS']
    dependency_of:
      description:
      - A list of services by their C(name) that depend on this service.
      type: list
      elements: str
      sample: ['upnphost', 'WMPNetworkSvc']
    description:
      description:
      - The description of the service.
      type: str
      sample: Example description of the Windows service.
    desktop_interact:
      description:
      - Whether the service can interact with the desktop, only valid for services running as C(SYSTEM).
      type: bool
      sample: false
    display_name:
      description:
      - The display name to be used by SCM to identify the service.
      type: str
      sample: Windows Remote Management (WS-Management)
    error_control:
      description:
      - The action to take if a service fails to start.
      - Common values are C(critical), C(ignore), C(normal), C(severe).
      type: str
      sample: normal
    failure_actions:
      description:
      - A list of failure actions to run in the event of a failure.
      type: list
      elements: dict
      contains:
        delay_ms:
          description:
          - The time to wait, in milliseconds, before performing the specified action.
          type: int
          sample: 120000
        type:
          description:
          - The action that will be performed.
          - Common values are C(none), C(reboot), C(restart), C(run_command).
          type: str
          sample: run_command
    failure_action_on_non_crash_failure:
      description:
      - Controls when failure actions are fired based on how the service was stopped.
      type: bool
      sample: false
    failure_command:
      description:
      - The command line that will be run when a C(run_command) failure action is fired.
      type: str
      sample: runme.exe
    failure_reboot_msg:
      description:
      - The message to be broadcast to server users before rebooting when a C(reboot) failure action is fired.
      type: str
      sample: Service failed, rebooting host.
    failure_reset_period_sec:
      description:
      - The time, in seconds, after which to reset the failure count to zero.
      type: int
      sample: 86400
    launch_protection:
      description:
      - The protection type of the service.
      - Common values are C(none), C(windows), C(windows_light), or C(antimalware_light).
      type: str
      sample: none
    load_order_group:
      description:
      - The name of the load ordering group to which the service belongs.
      - Will be an empty string if it does not belong to any group.
      type: str
      sample: My group
    name:
      description:
      - The name of the service.
      type: str
      sample: WinRM
    path:
      description:
      - The path to the service binary and any arguments used when starting the service.
      - The binary part can be quoted to ensure any spaces in path are not treated as arguments.
      type: str
      sample: 'C:\Windows\System32\svchost.exe -k netsvcs -p'
    pre_shutdown_timeout_ms:
      description:
      - The preshutdown timeout out value in milliseconds.
      type: int
      sample: 10000
    preferred_node:
      description:
      - The node number for the preferred node.
      - This will be C(null) if the Windows host has no NUMA configuration.
      type: int
      sample: 0
    process_id:
      description:
      - The process identifier of the running service.
      type: int
      sample: 5135
    required_privileges:
      description:
      - A list of privileges that the service requires and will run with
      type: list
      elements: str
      sample: ['SeBackupPrivilege', 'SeRestorePrivilege']
    service_exit_code:
      description:
      - A service-specific error code that is set while the service is starting or stopping.
      type: int
      sample: 0
    service_flags:
      description:
      - Shows more information about the behaviour of a running service.
      - Currently the only flag that can be set is C(runs_in_system_process).
      type: list
      elements: str
      sample: [ 'runs_in_system_process' ]
    service_type:
      description:
      - The type of service.
      - Common types are C(win32_own_process), C(win32_share_process), C(user_own_process), C(user_share_process),
        C(kernel_driver).
      type: str
      sample: win32_own_process
    sid_info:
      description:
      - The behavior of how the service's access token is generated and how to add the service SID to the token.
      - Common values are C(none), C(restricted), or C(unrestricted).
      type: str
      sample: none
    start_mode:
      description:
      - When the service is set to start.
      - Common values are C(auto), C(manual), C(disabled), C(delayed).
      type: str
      sample: auto
    state:
      description:
      - The current running state of the service.
      - Common values are C(stopped), C(start_pending), C(stop_pending), C(started), C(continue_pending),
        C(pause_pending), C(paused).
      type: str
      sample: started
    triggers:
      description:
      - A list of triggers defined for the service.
      type: list
      elements: dict
      contains:
        action:
          description:
          - The action to perform once triggered, can be C(start_service) or C(stop_service).
          type: str
          sample: start_service
        data_items:
          description:
          - A list of trigger data items that contain trigger specific data.
          - A trigger can contain 0 or multiple data items.
          type: list
          elements: dict
          contains:
            data:
              description:
              - The trigger data item value.
              - Can be a string, list of string, int, or base64 string of binary data.
              type: complex
              sample: named pipe
            type:
              description:
              - The type of C(data) for the trigger.
              - Common values are C(string), C(binary), C(level), C(keyword_any), or C(keyword_all).
              type: str
              sample: string
        sub_type:
          description:
          - The trigger event sub type that is specific to each C(type).
          - Common values are C(named_pipe_event), C(domain_join), C(domain_leave), C(firewall_port_open), and others.
          type: str
          sample:
        sub_type_guid:
          description:
          - The guid which represents the trigger sub type.
          type: str
          sample: 1ce20aba-9851-4421-9430-1ddeb766e809
        type:
          description:
          - The trigger event type.
          - Common values are C(custom), C(rpc_interface_event), C(domain_join), C(group_policy), and others.
          type: str
          sample: domain_join
    username:
      description:
      - The username used to run the service.
      - Can be null for user services and certain driver services.
      type: str
      sample: NT AUTHORITY\SYSTEM
    wait_hint_ms:
      description:
      - The estimated time in milliseconds required for a pending start, stop, pause,or continue operations.
      type: int
      sample: 0
    win32_exitcode:
      description:
      - The error code returned from the service binary once it has stopped.
      - When set to C(1066) then a service specific error is returned on C(service_exit_code).
      type: int
      sample: 0
'''