summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2017-11-03 09:55:03 +1000
committerJordan Borean <jborean93@gmail.com>2017-11-03 09:56:08 +1000
commite771b64f1b27b916a289b60695f6b56ba88198e9 (patch)
treecd4d1ff25fde51a5a1e8026160bf6f735efd8086
parent82c2da31beb4b571571902a8c54681434153ce4a (diff)
downloadansible-e771b64f1b27b916a289b60695f6b56ba88198e9.tar.gz
win_service: quoted path fix (#32469)
* win_service: fix for path in quotes * Added tests to verify behaviour doesn't regress (cherry picked from commit 5b1db00b65429594d6bc9ab8e107a7db288556e8)
-rw-r--r--lib/ansible/modules/windows/win_service.ps15
-rw-r--r--test/integration/targets/win_service/tasks/main.yml6
-rw-r--r--test/integration/targets/win_service/tasks/tests.yml31
3 files changed, 41 insertions, 1 deletions
diff --git a/lib/ansible/modules/windows/win_service.ps1 b/lib/ansible/modules/windows/win_service.ps1
index 3e5d71350a..97aa44e3d9 100644
--- a/lib/ansible/modules/windows/win_service.ps1
+++ b/lib/ansible/modules/windows/win_service.ps1
@@ -32,7 +32,7 @@ $display_name = Get-AnsibleParam -obj $params -name 'display_name' -type 'str'
$force_dependent_services = Get-AnsibleParam -obj $params -name 'force_dependent_services' -type 'bool' -default $false
$name = Get-AnsibleParam -obj $params -name 'name' -type 'str' -failifempty $true
$password = Get-AnsibleParam -obj $params -name 'password' -type 'str'
-$path = Get-AnsibleParam -obj $params -name 'path' -type 'path'
+$path = Get-AnsibleParam -obj $params -name 'path'
$start_mode = Get-AnsibleParam -obj $params -name 'start_mode' -type 'str' -validateset 'auto','manual','disabled','delayed'
$state = Get-AnsibleParam -obj $params -name 'state' -type 'str' -validateset 'started','stopped','restarted','absent','paused'
$username = Get-AnsibleParam -obj $params -name 'username' -type 'str'
@@ -51,6 +51,9 @@ if ($password -ne $null -and $username -eq $null) {
if ($desktop_interact -eq $true -and (-not ($username -eq "LocalSystem" -or $username -eq $null))) {
Fail-Json $result "Can only set 'desktop_interact' to true when 'username' equals 'LocalSystem'"
}
+if ($path -ne $null) {
+ $path = [System.Environment]::ExpandEnvironmentVariables($path)
+}
Function Get-ServiceInfo($name) {
# Need to get new objects so we have the latest info
diff --git a/test/integration/targets/win_service/tasks/main.yml b/test/integration/targets/win_service/tasks/main.yml
index d23b0507f8..a46a407b3c 100644
--- a/test/integration/targets/win_service/tasks/main.yml
+++ b/test/integration/targets/win_service/tasks/main.yml
@@ -51,3 +51,9 @@
- '{{test_win_service_name}}'
- TestServiceParent2
- TestServiceDependency
+
+ - name: remove test environment variable
+ win_environment:
+ name: TEST_SERVICE_PATH
+ level: machine
+ state: absent
diff --git a/test/integration/targets/win_service/tasks/tests.yml b/test/integration/targets/win_service/tasks/tests.yml
index bf31165a13..a41c838ad2 100644
--- a/test/integration/targets/win_service/tasks/tests.yml
+++ b/test/integration/targets/win_service/tasks/tests.yml
@@ -610,6 +610,37 @@
- not win_service_path_again|changed
- win_service_path_again.path == 'C:\\temp\\test.exe'
+- name: create test environment variable
+ win_environment:
+ name: TEST_SERVICE_PATH
+ value: C:\temp
+ level: machine
+ state: present
+
+- name: set service path with quotes and env var
+ win_service:
+ name: "{{test_win_service_name}}"
+ path: '"%TEST_SERVICE_PATH%\test.exe"'
+ register: win_service_env_quote_path
+
+- name: check that the quoted service path has been changed
+ assert:
+ that:
+ - win_service_env_quote_path|changed
+ - win_service_env_quote_path.path == '"C:\\temp\\test.exe"'
+
+- name: set service path with quotes and env var again
+ win_service:
+ name: "{{test_win_service_name}}"
+ path: '"%TEST_SERVICE_PATH%\test.exe"'
+ register: win_service_env_quote_path_again
+
+- name: check that the quoted service path has been changed again
+ assert:
+ that:
+ - not win_service_env_quote_path_again|changed
+ - win_service_env_quote_path_again.path == '"C:\\temp\\test.exe"'
+
- name: revert original service path back to normal
win_service:
name: "{{test_win_service_name}}"