win_nssm: restore support of string as dict form for app_parameters and remove support of literal YAML dict
This commit is contained in:
parent
ead882bb9b
commit
862855252b
3 changed files with 39 additions and 47 deletions
|
@ -36,8 +36,8 @@ if (($appParameters -ne $null) -and ($appParametersFree -ne $null))
|
|||
{
|
||||
Fail-Json $result "Use either app_parameters or app_parameteres_free_form, but not both"
|
||||
}
|
||||
if (($appParameters -ne $null) -and ($appParameters -isnot [System.Collections.Hashtable])) {
|
||||
Fail-Json -obj $result -message "The app_parameters parameter must be a dict"
|
||||
if (($appParameters -ne $null) -and ($appParameters -isnot [string])) {
|
||||
Fail-Json -obj $result -message "The app_parameters parameter must be a string representing a dictionary."
|
||||
}
|
||||
|
||||
Function Nssm-Invoke
|
||||
|
@ -171,6 +171,20 @@ Function Nssm-Install
|
|||
}
|
||||
}
|
||||
|
||||
Function ParseAppParameters()
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[AllowEmptyString()]
|
||||
[string]$appParameters
|
||||
)
|
||||
|
||||
$escapedAppParameters = $appParameters.TrimStart("@").TrimStart("{").TrimEnd("}").Replace("; ","`n").Replace("\","\\")
|
||||
|
||||
return ConvertFrom-StringData -StringData $escapedAppParameters
|
||||
}
|
||||
|
||||
Function Nssm-Update-AppParameters
|
||||
{
|
||||
[CmdletBinding()]
|
||||
|
@ -197,9 +211,9 @@ Function Nssm-Update-AppParameters
|
|||
|
||||
if ($null -ne $appParameters)
|
||||
{
|
||||
$appParametersHash = ParseAppParameters -appParameters $appParameters
|
||||
$appParamsArray = @()
|
||||
$appParameters.GetEnumerator() |
|
||||
% {
|
||||
$appParametersHash.GetEnumerator() | foreach {
|
||||
$key = $($_.Name)
|
||||
$val = $($_.Value)
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ options:
|
|||
- Path to receive error output.
|
||||
app_parameters:
|
||||
description:
|
||||
- Parameters to be passed to the application when it starts.
|
||||
- A string representing a dictionary of parameters to be passed to the application when it starts.
|
||||
- Use either this or C(app_parameters_free_form), not both.
|
||||
app_parameters_free_form:
|
||||
version_added: "2.3.0"
|
||||
|
@ -87,37 +87,25 @@ EXAMPLES = r'''
|
|||
application: C:\windows\foo.exe
|
||||
|
||||
# Install and start the foo service with a key-value pair argument
|
||||
# This will yield the following command: C:\windows\foo.exe bar "true"
|
||||
# This will yield the following command: C:\windows\foo.exe -bar true
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
app_parameters:
|
||||
bar: 'true'
|
||||
|
||||
# Install and start the foo service with a key-value pair argument, where the argument needs to start with a dash
|
||||
# This will yield the following command: C:\windows\\foo.exe -bar "true"
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
app_parameters:
|
||||
"-bar": 'true'
|
||||
app_parameters: -bar=true
|
||||
|
||||
# Install and start the foo service with a single parameter
|
||||
# This will yield the following command: C:\windows\\foo.exe bar
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
app_parameters:
|
||||
_: bar
|
||||
app_parameters: _=bar
|
||||
|
||||
# Install and start the foo service with a mix of single params, and key value pairs
|
||||
# This will yield the following command: C:\windows\\foo.exe bar -file output.bat
|
||||
# This will yield the following command: C:\windows\\foo.exe bar -file output.bat -foo false
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
app_parameters:
|
||||
_: bar
|
||||
"-file": "output.bat"
|
||||
app_parameters: _=bar; -file=output.bat; -foo=false
|
||||
|
||||
# Use the single line parameters option to specify an arbitrary string of parameters
|
||||
# for the service executable
|
||||
|
|
|
@ -187,12 +187,7 @@
|
|||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
app_parameters:
|
||||
foo: true
|
||||
'-file.out': 'output.bat'
|
||||
'-path': 'C:\with space\'
|
||||
'-str': 'test"quotes'
|
||||
_: bar
|
||||
app_parameters: foo=true; -file.out=output.bat; -path=C:\with space\; -str=test"quotes; _=bar
|
||||
register: mixed_params
|
||||
|
||||
- name: get result of install service with dict parameters
|
||||
|
@ -205,19 +200,14 @@
|
|||
- mixed_params.changed == true
|
||||
- (mixed_params_actual.stdout|from_json).Exists == true
|
||||
- (mixed_params_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: bar -str "test\"quotes" -file.out output.bat foo True -path "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (mixed_params_actual.stdout|from_json).Parameters.AppParameters == 'bar -str "test\\"quotes" -file.out output.bat foo True -path "C:\\with space\\\\"'
|
||||
# Expected value: bar -file.out output.bat -str "test\"quotes" foo true -path "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (mixed_params_actual.stdout|from_json).Parameters.AppParameters == 'bar -file.out output.bat -str "test\\"quotes" foo true -path "C:\\with space\\\\"'
|
||||
|
||||
- name: install service with dict parameters (idempotent)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
app_parameters:
|
||||
foo: true
|
||||
'-file.out': 'output.bat'
|
||||
'-path': 'C:\with space\'
|
||||
'-str': 'test"quotes'
|
||||
_: bar
|
||||
app_parameters: foo=true; -file.out=output.bat; -path=C:\with space\; -str=test"quotes; _=bar
|
||||
register: mixed_params_again
|
||||
|
||||
- name: get result of install service with dict parameters (idempotent)
|
||||
|
@ -230,8 +220,8 @@
|
|||
- mixed_params_again.changed == false
|
||||
- (mixed_params_again_actual.stdout|from_json).Exists == true
|
||||
- (mixed_params_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: bar -str "test\"quotes" -file.out output.bat foo True -path "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (mixed_params_again_actual.stdout|from_json).Parameters.AppParameters == 'bar -str "test\\"quotes" -file.out output.bat foo True -path "C:\\with space\\\\"'
|
||||
# Expected value: bar -file.out output.bat -str "test\"quotes" foo true -path "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (mixed_params_again_actual.stdout|from_json).Parameters.AppParameters == 'bar -file.out output.bat -str "test\\"quotes" foo true -path "C:\\with space\\\\"'
|
||||
|
||||
- name: remove service
|
||||
win_nssm:
|
||||
|
|
Loading…
Reference in a new issue