Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
1a3a3af0
Commit
1a3a3af0
authored
Jul 03, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8015 from cchurch/test_win_service
win_service module updates and tests
parents
c2ac8fda
12a0f4ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
219 additions
and
2 deletions
+219
-2
library/windows/win_service.ps1
+17
-2
test/integration/roles/test_win_service/defaults/main.yml
+5
-0
test/integration/roles/test_win_service/tasks/main.yml
+196
-0
test/integration/test_winrm.yml
+1
-0
No files found.
library/windows/win_service.ps1
View file @
1a3a3af0
...
@@ -48,14 +48,27 @@ $svc = Get-Service -Name $svcName -ErrorAction SilentlyContinue
...
@@ -48,14 +48,27 @@ $svc = Get-Service -Name $svcName -ErrorAction SilentlyContinue
If
(
-not
$svc
)
{
If
(
-not
$svc
)
{
Fail-Json
$result
"Service '
$svcName
' not installed"
Fail-Json
$result
"Service '
$svcName
' not installed"
}
}
# Use service name instead of display name for remaining actions.
If
(
$svcName
-ne
$svc
.ServiceName
)
{
$svcName
=
$svc
.ServiceName
}
If
(
$startMode
)
{
Set
-Attr
$result
"name"
$svc
.ServiceName
$svcMode
=
Get-WmiObject
-Class Win32_Service -Property StartMode -Filter
"Name='
$svcName
'"
Set
-Attr
$result
"display_name"
$svc
.DisplayName
$svcMode
=
Get-WmiObject
-Class Win32_Service -Property StartMode -Filter
"Name='
$svcName
'"
If
(
$startMode
)
{
If
(
$svcMode
.StartMode.ToLower
()
-ne
$startMode
)
{
If
(
$svcMode
.StartMode.ToLower
()
-ne
$startMode
)
{
Set-Service
-Name
$svcName
-StartupType
$startMode
Set-Service
-Name
$svcName
-StartupType
$startMode
Set
-Attr
$result
"changed"
$true
Set
-Attr
$result
"changed"
$true
Set
-Attr
$result
"start_mode"
$startMode
}
}
Else
{
Set
-Attr
$result
"start_mode"
$svcMode
.StartMode.ToLower
()
}
}
Else
{
Set
-Attr
$result
"start_mode"
$svcMode
.StartMode.ToLower
()
}
}
If
(
$state
)
{
If
(
$state
)
{
...
@@ -87,5 +100,7 @@ If ($state) {
...
@@ -87,5 +100,7 @@ If ($state) {
Set
-Attr
$result
"changed"
$true
;
Set
-Attr
$result
"changed"
$true
;
}
}
}
}
$svc
.Refresh
()
Set
-Attr
$result
"state"
$svc
.Status.ToString
()
.ToLower
()
Exit
-Json
$result
;
Exit
-Json
$result
;
test/integration/roles/test_win_service/defaults/main.yml
0 → 100644
View file @
1a3a3af0
---
# Service is commonly available and usually disabled/stopped by default.
test_win_service_name
:
SSDPSRV
test_win_service_display_name
:
"
SSDP
Discovery"
test/integration/roles/test_win_service/tasks/main.yml
0 → 100644
View file @
1a3a3af0
# test code for the win_service module
# (c) 2014, Chris Church <chris@ninemoreminutes.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-
name
:
test win_service module with short name
win_service
:
name="{{ test_win_service_name }}"
register
:
win_service_name
-
name
:
check win_service result with short name
assert
:
that
:
-
"
not
win_service_name|changed"
-
"
win_service_name.name"
-
"
win_service_name.display_name"
-
"
win_service_name.start_mode"
-
"
win_service_name.state"
-
name
:
test win_service module with display name
win_service
:
name="{{ test_win_service_display_name }}"
register
:
win_service_display_name
-
name
:
check win_service result with display name
assert
:
that
:
-
"
not
win_service_display_name|changed"
-
"
win_service_display_name.name"
-
"
win_service_display_name.display_name"
-
"
win_service_display_name.start_mode"
-
"
win_service_display_name.state"
-
name
:
test win_service module with invalid name
win_service
:
name="iamnotaservice"
ignore_errors
:
true
register
:
win_service_invalid
-
name
:
check win_service result with invalid_name
assert
:
that
:
-
"
win_service_invalid|failed"
-
"
win_service_invalid.msg"
-
name
:
make sure the service is stopped and disabled
win_service
:
name="{{ test_win_service_name }}" state=stopped start_mode=disabled
register
:
win_service_stopped_disabled
-
name
:
check result of disabling and stopping the service
assert
:
that
:
-
"
win_service_stopped_disabled.start_mode
==
'disabled'"
-
"
win_service_stopped_disabled.state
==
'stopped'"
-
name
:
try to start the disabled service
win_service
:
name="{{ test_win_service_name }}" state=started
register
:
win_service_start_disabled
ignore_errors
:
true
-
name
:
check that starting the disabled service fails
assert
:
that
:
-
"
win_service_start_disabled|failed"
-
"
win_service_start_disabled.msg"
-
name
:
enable the service for manual startup
win_service
:
name="{{ test_win_service_name }}" start_mode=manual
register
:
win_service_manual_start_mode
-
name
:
check that enabling the service succeeds for manual startup
assert
:
that
:
-
"
win_service_manual_start_mode|changed"
-
"
win_service_manual_start_mode.start_mode
==
'manual'"
-
"
win_service_manual_start_mode.state
==
'stopped'"
-
name
:
enable the service again for manual startup
win_service
:
name="{{ test_win_service_name }}" start_mode=manual
register
:
win_service_manual_start_mode_again
-
name
:
check that enabling the service succeeds for manual startup
assert
:
that
:
-
"
not
win_service_manual_start_mode_again|changed"
-
"
win_service_manual_start_mode_again.start_mode
==
'manual'"
-
"
win_service_manual_start_mode_again.state
==
'stopped'"
-
name
:
try to start the manual service
win_service
:
name="{{ test_win_service_name }}" state=started
register
:
win_service_start_manual
-
name
:
check that starting the manual service succeeds
assert
:
that
:
-
"
win_service_start_manual|changed"
-
"
win_service_start_manual.start_mode
==
'manual'"
-
"
win_service_start_manual.state
==
'running'"
-
name
:
try to start the manual service again
win_service
:
name="{{ test_win_service_name }}" state=started
register
:
win_service_start_manual_again
-
name
:
check that starting the manual service again succeeds without changes
assert
:
that
:
-
"
not
win_service_start_manual_again|changed"
-
"
win_service_start_manual_again.start_mode
==
'manual'"
-
"
win_service_start_manual_again.state
==
'running'"
-
name
:
enable the service for automatic startup
win_service
:
name="{{ test_win_service_name }}" start_mode=auto
register
:
win_service_auto_start_mode
-
name
:
check that enabling the service succeeds for automatic startup
assert
:
that
:
-
"
win_service_auto_start_mode|changed"
-
"
win_service_auto_start_mode.start_mode
==
'auto'"
-
"
win_service_auto_start_mode.state
==
'running'"
-
name
:
enable the service again for automatic startup
win_service
:
name="{{ test_win_service_name }}" start_mode=auto
register
:
win_service_auto_start_mode_again
-
name
:
check that enabling the service succeeds for automatic startup without changes
assert
:
that
:
-
"
not
win_service_auto_start_mode_again|changed"
-
"
win_service_auto_start_mode_again.start_mode
==
'auto'"
-
"
win_service_auto_start_mode_again.state
==
'running'"
-
name
:
restart the service
win_service
:
name="{{ test_win_service_name }}" state=restarted
register
:
win_service_restart_auto
-
name
:
check that restarting the service succeeds with changes
assert
:
that
:
-
"
win_service_restart_auto|changed"
-
"
win_service_restart_auto.start_mode
==
'auto'"
-
"
win_service_restart_auto.state
==
'running'"
-
name
:
disable the service again
win_service
:
name="{{ test_win_service_name }}" start_mode=disabled
register
:
win_service_disabled_start_mode
-
name
:
check that disabling the service succeeds, service is still running
assert
:
that
:
-
"
win_service_disabled_start_mode|changed"
-
"
win_service_disabled_start_mode.start_mode
==
'disabled'"
-
"
win_service_disabled_start_mode.state
==
'running'"
-
name
:
disable the service again
win_service
:
name="{{ test_win_service_name }}" start_mode=disabled
register
:
win_service_disabled_start_mode_again
-
name
:
check that disabling the service succeeds again
assert
:
that
:
-
"
not
win_service_disabled_start_mode_again|changed"
-
"
win_service_disabled_start_mode_again.start_mode
==
'disabled'"
-
"
win_service_disabled_start_mode_again.state
==
'running'"
-
name
:
stop the service
win_service
:
name="{{ test_win_service_name }}" state=stopped
register
:
win_service_stop_disabled
-
name
:
check that stopping the service succeeds with changes
assert
:
that
:
-
"
win_service_stop_disabled|changed"
-
"
win_service_stop_disabled.start_mode
==
'disabled'"
-
"
win_service_stop_disabled.state
==
'stopped'"
-
name
:
stop the service again
win_service
:
name="{{ test_win_service_name }}" state=stopped
register
:
win_service_stop_disabled_again
-
name
:
check that stopping the service again succeeds without changes
assert
:
that
:
-
"
not
win_service_stop_disabled_again|changed"
-
"
win_service_stop_disabled_again.start_mode
==
'disabled'"
-
"
win_service_stop_disabled_again.state
==
'stopped'"
test/integration/test_winrm.yml
View file @
1a3a3af0
...
@@ -28,3 +28,4 @@
...
@@ -28,3 +28,4 @@
-
{
role
:
test_win_stat
,
tags
:
test_win_stat
}
-
{
role
:
test_win_stat
,
tags
:
test_win_stat
}
-
{
role
:
test_win_get_url
,
tags
:
test_win_get_url
}
-
{
role
:
test_win_get_url
,
tags
:
test_win_get_url
}
-
{
role
:
test_win_msi
,
tags
:
test_win_msi
}
-
{
role
:
test_win_msi
,
tags
:
test_win_msi
}
-
{
role
:
test_win_service
,
tags
:
test_win_service
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment