mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
win_service_stat: Added module (#21944)
This commit is contained in:
parent
c98647ccf8
commit
3da806f32a
6 changed files with 273 additions and 0 deletions
1
test/integration/targets/win_service_stat/aliases
Normal file
1
test/integration/targets/win_service_stat/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group2
|
86
test/integration/targets/win_service_stat/tasks/main.yml
Normal file
86
test/integration/targets/win_service_stat/tasks/main.yml
Normal file
|
@ -0,0 +1,86 @@
|
|||
---
|
||||
# Until changes are merged into win_service to create a new module we will need
|
||||
# to do it ourselves
|
||||
- name: stop test services before test
|
||||
win_command: sc stop TestService
|
||||
ignore_errors: True
|
||||
|
||||
- name: make sure we clean up any test services
|
||||
win_command: sc delete TestService
|
||||
ignore_errors: True
|
||||
|
||||
- name: get stats on service that doesn't exist
|
||||
win_service_stat:
|
||||
name: TestService
|
||||
register: missing_service
|
||||
|
||||
- name: assert missing service doesn't exist
|
||||
assert:
|
||||
that:
|
||||
- not missing_service|changed
|
||||
- missing_service.exists == False
|
||||
|
||||
- name: create a new test service
|
||||
win_command: powershell.exe "New-Service -Name TestService -BinaryPathname C:\Windows\System32\snmptrap.exe"
|
||||
|
||||
- name: get stats on newly created service
|
||||
win_service_stat:
|
||||
name: TestService
|
||||
register: new_service
|
||||
|
||||
- name: assert new service results are what we expect
|
||||
assert:
|
||||
that:
|
||||
- not new_service|changed
|
||||
- new_service.exists == True
|
||||
- new_service.depended_by == []
|
||||
- new_service.dependencies == []
|
||||
- new_service.description == ""
|
||||
- new_service.desktop_interact == False
|
||||
- new_service.display_name == 'TestService'
|
||||
- new_service.name == 'TestService'
|
||||
- new_service.path == 'C:\Windows\System32\snmptrap.exe'
|
||||
- new_service.start_mode == 'auto'
|
||||
- new_service.state == 'stopped'
|
||||
- new_service.username == 'LocalSystem'
|
||||
|
||||
- name: change details about the service
|
||||
win_command: powershell.exe "Set-Service -Name TestService -DisplayName NewDisplayName -Description description -StartupType Manual"
|
||||
|
||||
- name: get stats on changed service
|
||||
win_service_stat:
|
||||
name: TestService
|
||||
register: changed_service
|
||||
|
||||
- name: assert changed service details have changed
|
||||
assert:
|
||||
that:
|
||||
- not changed_service|changed
|
||||
- changed_service.exists == True
|
||||
- changed_service.description == 'description'
|
||||
- changed_service.display_name == 'NewDisplayName'
|
||||
- changed_service.start_mode == 'manual'
|
||||
|
||||
- name: start the service
|
||||
win_service:
|
||||
name: TestService
|
||||
state: started
|
||||
register: started_service
|
||||
|
||||
- name: get stats on started service
|
||||
win_service_stat:
|
||||
name: TestService
|
||||
register: started_service
|
||||
|
||||
- name: assert service stats is started
|
||||
assert:
|
||||
that:
|
||||
- started_service.state == 'running'
|
||||
|
||||
# TODO: Change other service info through win_service once we can do it with a module
|
||||
|
||||
- name: stop test services before deleting
|
||||
win_command: sc stop TestService
|
||||
|
||||
- name: clean up test service at the end
|
||||
win_command: sc delete TestService
|
Loading…
Add table
Add a link
Reference in a new issue