win_nssm: refactor to fix issues, support check mode and add more features (#45693)
* win_nssm: rename cmdlets to use approved verbs, rename service name parameters * win_nssm: improve code style and cmdlets ordering * win_nssm: always escape all command line parameters with Argv-ToString fix error when the service name contains quotes * win_nssm: use Fail-Json instead of exceptions and remove global try/catch * win_nssm: small refactoring, inline some functions * win_nssm: refactoring - add a generic cmdlet to idempotently set any nssm service parameter * win_nssm: refactoring - inline some functions To make the code more malleable for future changes * win_nssm: change application, stdout_file and stderr_file options type to path * win_nssm: deprecates app_parameters, rename app_parameters_free_form to arguments, and add support for list of parameters * win_nssm: add support of check mode * win_nssm: add working_directory option * win_nssm: add display_name and description options * win_nssm: minor changes * win_nssm: remove some sanity exclusions * win_nssm: avoid using aliases and minor style fixes * win_nssm: doc and ui improvements * win_nssm: remove sanity exclusions * win_nssm: minor revision * win_nssm: deprecates dependencies, start_mode, user and password parameters and some choices of state in favor of win_service * win_nssm: fix style * win_nssm: add executable option to specify the location of the NSSM utility * win_nssm: add missing parameter types * win_nssm: add diff mode support * win_nssm: avoid displaying depreciation warning if default value is assigned * win_nssm: fix variable scope * win_nssm: use the explicit -LiteralPath parameter name instead of -Path * win_nssm: fix documentation * win_nssm: add porting guide entries * win_nssm: add changelog fragment
This commit is contained in:
parent
eff1f8851c
commit
09979e899f
6 changed files with 654 additions and 666 deletions
13
changelogs/fragments/win_nssm.yaml
Normal file
13
changelogs/fragments/win_nssm.yaml
Normal file
|
@ -0,0 +1,13 @@
|
|||
minor_changes:
|
||||
- win_nssm - Add the ``executable`` option to specify the location of the NSSM utility.
|
||||
- win_nssm - Add the ``working_directory``, ``display_name`` and ``description`` options.
|
||||
- win_nssm - Add support for check and diff modes.
|
||||
- win_nssm - Change default value for ``state`` from ``start`` to ``present``.
|
||||
|
||||
bugfixes:
|
||||
- win_nssm - Fix several escaping and quoting issues of paths and parameters.
|
||||
|
||||
deprecated_features:
|
||||
- win_nssm - Deprecate ``dependencies``, ``start_mode``, ``user``, and ``password`` options, in favor of using the ``win_service`` module.
|
||||
- win_nssm - Deprecate ``start``, ``stop``, and ``restart`` values for ``state`` option, in favor of using the ``win_service`` module.
|
||||
- win_nssm - Deprecate ``app_parameters`` option in favor of ``arguments``.
|
|
@ -312,6 +312,24 @@ Noteworthy module changes
|
|||
|
||||
* The ``win_psexec`` has deprecated the undocumented ``extra_opts`` module option. This will be removed in Ansible 2.10.
|
||||
|
||||
* The ``win_nssm`` module has deprecated the following options in favor of using the ``win_service`` module to configure the service after installing it with ``win_nssm``:
|
||||
* ``dependencies``, use ``dependencies`` of ``win_service`` instead
|
||||
* ``start_mode``, use ``start_mode`` of ``win_service`` instead
|
||||
* ``user``, use ``username`` of ``win_service`` instead
|
||||
* ``password``, use ``password`` of ``win_service`` instead
|
||||
These options will be removed in Ansible 2.12.
|
||||
|
||||
* The ``win_nssm`` module has also deprecated the ``start``, ``stop``, and ``restart`` values of the ``status`` option.
|
||||
You should use the ``win_service`` module to control the running state of the service. This will be removed in Ansible 2.12.
|
||||
|
||||
* The ``status`` module option for ``win_nssm`` has changed its default value to ``present``. Before, the default was ``start``.
|
||||
Consequently, the service is no longer started by default after creation with ``win_nssm``, and you should use
|
||||
the ``win_service`` module to start it if needed.
|
||||
|
||||
* The ``app_parameters`` module option for ``win_nssm`` has been deprecated; use ``argument`` instead. This will be removed in Ansible 2.12.
|
||||
|
||||
* The ``app_parameters_free_form`` module option for ``win_nssm`` has been aliased to the new ``arguments`` option.
|
||||
|
||||
* The ``win_dsc`` module will now validate the input options for a DSC resource. In previous versions invalid options
|
||||
would be ignored but are now not.
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,9 +15,10 @@ DOCUMENTATION = r'''
|
|||
---
|
||||
module: win_nssm
|
||||
version_added: "2.0"
|
||||
short_description: NSSM - the Non-Sucking Service Manager
|
||||
short_description: Install a service using NSSM
|
||||
description:
|
||||
- nssm is a service helper which doesn't suck. See U(https://nssm.cc/) for more information.
|
||||
- Install a Windows service using the NSSM wrapper.
|
||||
- NSSM is a service helper which doesn't suck. See U(https://nssm.cc/) for more information.
|
||||
requirements:
|
||||
- "nssm >= 2.24.0 # (install via M(win_chocolatey)) C(win_chocolatey: name=nssm)"
|
||||
options:
|
||||
|
@ -29,50 +30,75 @@ options:
|
|||
state:
|
||||
description:
|
||||
- State of the service on the system.
|
||||
- Note that NSSM actions like "pause", "continue", "rotate" do not fit the declarative style of ansible, so these should be implemented via the
|
||||
ansible command module.
|
||||
- Values C(started), C(stopped), and C(restarted) are deprecated since v2.8,
|
||||
please use the M(win_service) module instead to start, stop or restart the service.
|
||||
type: str
|
||||
choices: [ absent, present, started, stopped, restarted ]
|
||||
default: started
|
||||
default: present
|
||||
application:
|
||||
description:
|
||||
- The application binary to run as a service
|
||||
- "Specify this whenever the service may need to be installed (state: present, started, stopped, restarted)"
|
||||
- "Note that the application name must look like the following, if the directory includes spaces:"
|
||||
- 'nssm install service "C:\\Program Files\\app.exe\\" "C:\\Path with spaces\\"'
|
||||
- >
|
||||
See commit 0b386fc1984ab74ee59b7bed14b7e8f57212c22b in the nssm.git project for more info:
|
||||
U(https://git.nssm.cc/?p=nssm.git;a=commit;h=0b386fc1984ab74ee59b7bed14b7e8f57212c22b)
|
||||
- Required when I(state) is C(present), C(started), C(stopped), or C(restarted).
|
||||
type: path
|
||||
executable:
|
||||
description:
|
||||
- The location of the NSSM utility (in case it is not located in your PATH).
|
||||
type: path
|
||||
default: nssm.exe
|
||||
version_added: "2.8.0"
|
||||
description:
|
||||
description:
|
||||
- The description to set for the service.
|
||||
type: str
|
||||
version_added: "2.8.0"
|
||||
display_name:
|
||||
description:
|
||||
- The display name to set for the service.
|
||||
type: str
|
||||
version_added: "2.8.0"
|
||||
working_directory:
|
||||
version_added: "2.8.0"
|
||||
description:
|
||||
- The working directory to run the service executable from (defaults to the directory containing the application binary)
|
||||
type: path
|
||||
aliases: [ app_directory, chdir ]
|
||||
stdout_file:
|
||||
description:
|
||||
- Path to receive output.
|
||||
type: str
|
||||
type: path
|
||||
stderr_file:
|
||||
description:
|
||||
- Path to receive error output.
|
||||
type: str
|
||||
type: path
|
||||
app_parameters:
|
||||
description:
|
||||
- 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.
|
||||
- DEPRECATED since v2.8, please use I(arguments) instead.
|
||||
- This is mutually exclusive with I(arguments).
|
||||
type: str
|
||||
app_parameters_free_form:
|
||||
arguments:
|
||||
description:
|
||||
- Single string of parameters to be passed to the service.
|
||||
- Use either this or C(app_parameters), not both.
|
||||
- Parameters to be passed to the application when it starts.
|
||||
- This can be either a simple string or a list.
|
||||
- This parameter was renamed from I(app_parameters_free_form) in 2.8.
|
||||
- This is mutually exclusive with I(app_parameters).
|
||||
aliases: [ app_parameters_free_form ]
|
||||
type: str
|
||||
version_added: "2.3"
|
||||
dependencies:
|
||||
description:
|
||||
- Service dependencies that has to be started to trigger startup, separated by comma.
|
||||
- DEPRECATED since v2.8, please use the M(win_service) module instead.
|
||||
type: list
|
||||
user:
|
||||
description:
|
||||
- User to be used for service startup.
|
||||
- DEPRECATED since v2.8, please use the M(win_service) module instead.
|
||||
type: str
|
||||
password:
|
||||
description:
|
||||
- Password to be used for service startup.
|
||||
- DEPRECATED since v2.8, please use the M(win_service) module instead.
|
||||
type: str
|
||||
start_mode:
|
||||
description:
|
||||
|
@ -80,84 +106,66 @@ options:
|
|||
- C(delayed) causes a delayed but automatic start after boot (added in version 2.5).
|
||||
- C(manual) means that the service will start only when another service needs it.
|
||||
- C(disabled) means that the service will stay off, regardless if it is needed or not.
|
||||
- DEPRECATED since v2.8, please use the M(win_service) module instead.
|
||||
type: str
|
||||
choices: [ auto, delayed, disabled, manual ]
|
||||
default: auto
|
||||
seealso:
|
||||
- module: win_service
|
||||
- module: win_service
|
||||
notes:
|
||||
- The service will NOT be started after its creation when C(state=present).
|
||||
- Once the service is created, you can use the M(win_service) module to start it or configure
|
||||
some additionals properties, such as its startup type, dependencies, service account, and so on.
|
||||
author:
|
||||
- Adam Keech (@smadam813)
|
||||
- George Frank (@georgefrank)
|
||||
- Hans-Joachim Kliemeck (@h0nIg)
|
||||
- Michael Wild (@themiwi)
|
||||
- Kevin Subileau (@ksubileau)
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
# Install and start the foo service
|
||||
- win_nssm:
|
||||
name: foo
|
||||
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
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
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
|
||||
|
||||
# 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 -foo false
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
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
|
||||
- name: Make sure the Consul service runs
|
||||
- name: Install the foo service
|
||||
win_nssm:
|
||||
name: consul
|
||||
application: C:\consul\consul.exe
|
||||
app_parameters_free_form: agent -config-dir=C:\consul\config
|
||||
stdout_file: C:\consul\log.txt
|
||||
stderr_file: C:\consul\error.txt
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
|
||||
# Install and start the foo service, redirecting stdout and stderr to the same file
|
||||
- win_nssm:
|
||||
# This will yield the following command: C:\windows\foo.exe bar "true"
|
||||
- name: Install the Consul service with a list of parameters
|
||||
win_nssm:
|
||||
name: Consul
|
||||
application: C:\consul\consul.exe
|
||||
arguments:
|
||||
- agent
|
||||
- -config-dir=C:\consul\config
|
||||
|
||||
# This is strictly equivalent to the previous example
|
||||
- name: Install the Consul service with an arbitrary string of parameters
|
||||
win_nssm:
|
||||
name: Consul
|
||||
application: C:\consul\consul.exe
|
||||
arguments: agent -config-dir=C:\consul\config
|
||||
|
||||
|
||||
# Install the foo service, an then configure and start it with win_service
|
||||
- name: Install the foo service, redirecting stdout and stderr to the same file
|
||||
win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
stdout_file: C:\windows\foo.log
|
||||
stderr_file: C:\windows\foo.log
|
||||
|
||||
# Install and start the foo service, but wait for dependencies tcpip and adf
|
||||
- win_nssm:
|
||||
- name: Configure and start the foo service using win_service
|
||||
win_service:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
dependencies: 'adf,tcpip'
|
||||
|
||||
# Install and start the foo service with dedicated user
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
dependencies: [ adf, tcpip ]
|
||||
user: foouser
|
||||
password: secret
|
||||
|
||||
# Install the foo service but do not start it automatically
|
||||
- win_nssm:
|
||||
name: foo
|
||||
application: C:\windows\foo.exe
|
||||
state: present
|
||||
start_mode: manual
|
||||
state: started
|
||||
|
||||
# Remove the foo service
|
||||
- win_nssm:
|
||||
- name: Remove the foo service
|
||||
win_nssm:
|
||||
name: foo
|
||||
state: absent
|
||||
'''
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
set_fact:
|
||||
test_service_cmd: |
|
||||
$res = @{}
|
||||
$srvobj = Get-WmiObject Win32_Service -Filter "Name=""$service""" | Select Name,PathName,StartMode,StartName,State
|
||||
$srvobj = Get-WmiObject Win32_Service -Filter "Name=""$service""" | Select Name,DisplayName,Description,PathName,StartMode,StartName,State
|
||||
if ($srvobj) {
|
||||
$srvobj | Get-Member -MemberType *Property | % { $res.($_.name) = $srvobj.($_.name) }
|
||||
$res.Exists = $true
|
||||
$res.Dependencies = Get-WmiObject -Query "Associators of {Win32_Service.Name=""$service""} Where AssocClass=Win32_DependentService" | select -ExpandProperty Name
|
||||
$res.Dependencies = @(Get-WmiObject -Query "Associators of {Win32_Service.Name=""$service""} Where AssocClass=Win32_DependentService" | select -ExpandProperty Name)
|
||||
$res.Parameters = @{}
|
||||
$srvkey = "HKLM:\SYSTEM\CurrentControlSet\Services\$service\Parameters"
|
||||
Get-Item "$srvkey" | Select-Object -ExpandProperty property | % { $res.Parameters.$_ = (Get-ItemProperty -Path "$srvkey" -Name $_).$_}
|
||||
|
@ -16,6 +16,24 @@
|
|||
}
|
||||
ConvertTo-Json -InputObject $res -Compress
|
||||
|
||||
- name: install service (check mode)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
state: present
|
||||
register: install_service_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of install service (check mode)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: install_service_check_actual
|
||||
|
||||
- name: assert results of install service (check mode)
|
||||
assert:
|
||||
that:
|
||||
- install_service_check.changed == true
|
||||
- (install_service_check_actual.stdout|from_json).Exists == false
|
||||
|
||||
- name: install service
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
|
@ -35,6 +53,7 @@
|
|||
- (install_service_actual.stdout|from_json).State == 'Stopped'
|
||||
- (install_service_actual.stdout|from_json).StartMode == 'Auto'
|
||||
- (install_service_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_service_actual.stdout|from_json).Parameters.AppDirectory == "C:\Windows\System32"
|
||||
|
||||
- name: test install service (idempotent)
|
||||
win_nssm:
|
||||
|
@ -55,6 +74,7 @@
|
|||
- (install_service_again_actual.stdout|from_json).State == 'Stopped'
|
||||
- (install_service_again_actual.stdout|from_json).StartMode == 'Auto'
|
||||
- (install_service_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_service_again_actual.stdout|from_json).Parameters.AppDirectory == "C:\Windows\System32"
|
||||
|
||||
- name: install and start service
|
||||
win_nssm:
|
||||
|
@ -75,12 +95,52 @@
|
|||
- (install_start_service_actual.stdout|from_json).State == 'Running'
|
||||
- (install_start_service_actual.stdout|from_json).StartMode == 'Auto'
|
||||
- (install_start_service_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_start_service_actual.stdout|from_json).Parameters.AppDirectory == "C:\Windows\System32"
|
||||
|
||||
- name: install and start service with more parameters (check mode)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
display_name: Ansible testing
|
||||
description: win_nssm test service
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
start_mode: manual
|
||||
working_directory: '{{ test_win_nssm_path }}'
|
||||
dependencies: 'tcpip,dnscache'
|
||||
user: '{{ test_win_nssm_username }}'
|
||||
password: '{{ test_win_nssm_password }}'
|
||||
stdout_file: '{{ test_win_nssm_path }}\log.txt'
|
||||
stderr_file: '{{ test_win_nssm_path }}\error.txt'
|
||||
state: started
|
||||
register: install_service_complex_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of install and start service with more parameters (check mode)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: install_service_complex_check_actual
|
||||
|
||||
- name: assert results of install and start service with more parameters (check mode)
|
||||
assert:
|
||||
that:
|
||||
- install_service_complex_check.changed == true
|
||||
- (install_service_complex_check_actual.stdout|from_json).Exists == true
|
||||
- (install_service_complex_check_actual.stdout|from_json).DisplayName == '{{ test_service_name }}'
|
||||
- (install_service_complex_check_actual.stdout|from_json).Description is none
|
||||
- (install_service_complex_check_actual.stdout|from_json).StartMode != 'Manual'
|
||||
- (install_service_complex_check_actual.stdout|from_json).StartName != '.\\' + test_win_nssm_username
|
||||
- (install_service_complex_check_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_service_complex_check_actual.stdout|from_json).Parameters.AppDirectory == "C:\Windows\System32"
|
||||
- '"AppStdout" not in (install_service_complex_check_actual.stdout|from_json).Parameters'
|
||||
- '"AppStderr" not in (install_service_complex_check_actual.stdout|from_json).Parameters'
|
||||
- (install_service_complex_check_actual.stdout|from_json).Dependencies|length == 0
|
||||
|
||||
- name: install and start service with more parameters
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
display_name: Ansible testing
|
||||
description: win_nssm test service
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
start_mode: manual
|
||||
working_directory: '{{ test_win_nssm_path }}'
|
||||
dependencies: 'tcpip,dnscache'
|
||||
user: '{{ test_win_nssm_username }}'
|
||||
password: '{{ test_win_nssm_password }}'
|
||||
|
@ -98,10 +158,13 @@
|
|||
that:
|
||||
- install_service_complex.changed == true
|
||||
- (install_service_complex_actual.stdout|from_json).Exists == true
|
||||
- (install_service_complex_actual.stdout|from_json).DisplayName == 'Ansible testing'
|
||||
- (install_service_complex_actual.stdout|from_json).Description == 'win_nssm test service'
|
||||
- (install_service_complex_actual.stdout|from_json).State == 'Running'
|
||||
- (install_service_complex_actual.stdout|from_json).StartMode == 'Manual'
|
||||
- (install_service_complex_actual.stdout|from_json).StartName == '.\\' + test_win_nssm_username
|
||||
- (install_service_complex_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_service_complex_actual.stdout|from_json).Parameters.AppDirectory == test_win_nssm_path
|
||||
- (install_service_complex_actual.stdout|from_json).Parameters.AppStdout == test_win_nssm_path + '\\log.txt'
|
||||
- (install_service_complex_actual.stdout|from_json).Parameters.AppStderr == test_win_nssm_path + '\\error.txt'
|
||||
- (install_service_complex_actual.stdout|from_json).Dependencies|length == 2
|
||||
|
@ -111,8 +174,11 @@
|
|||
- name: install and start service with more parameters (idempotent)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
display_name: Ansible testing
|
||||
description: win_nssm test service
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
start_mode: manual
|
||||
working_directory: '{{ test_win_nssm_path }}'
|
||||
# Dependencies order should not trigger a change
|
||||
dependencies: 'dnscache,tcpip'
|
||||
user: '{{ test_win_nssm_username }}'
|
||||
|
@ -131,70 +197,76 @@
|
|||
that:
|
||||
- install_service_complex_again.changed == false
|
||||
- (install_service_complex_again_actual.stdout|from_json).Exists == true
|
||||
- (install_service_complex_again_actual.stdout|from_json).DisplayName == 'Ansible testing'
|
||||
- (install_service_complex_again_actual.stdout|from_json).Description == 'win_nssm test service'
|
||||
- (install_service_complex_again_actual.stdout|from_json).State == 'Running'
|
||||
- (install_service_complex_again_actual.stdout|from_json).StartMode == 'Manual'
|
||||
- (install_service_complex_again_actual.stdout|from_json).StartName == '.\\' + test_win_nssm_username
|
||||
- (install_service_complex_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
- (install_service_complex_again_actual.stdout|from_json).Parameters.AppDirectory == test_win_nssm_path
|
||||
- (install_service_complex_again_actual.stdout|from_json).Parameters.AppStdout == test_win_nssm_path + '\\log.txt'
|
||||
- (install_service_complex_again_actual.stdout|from_json).Parameters.AppStderr == test_win_nssm_path + '\\error.txt'
|
||||
- (install_service_complex_again_actual.stdout|from_json).Dependencies|length == 2
|
||||
- '"Tcpip" in (install_service_complex_again_actual.stdout|from_json).Dependencies'
|
||||
- '"Dnscache" in (install_service_complex_again_actual.stdout|from_json).Dependencies'
|
||||
|
||||
- name: install service with free form parameters
|
||||
- name: install service with string form parameters
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
app_parameters_free_form: '-v -Dcom.test.string=value "C:\with space\\"'
|
||||
arguments: '-v -Dtest.str=value "C:\with space\\"'
|
||||
state: present
|
||||
register: free_params
|
||||
register: str_params
|
||||
|
||||
- name: get result of install service with free form parameters
|
||||
- name: get result of install service with string form parameters
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: free_params_actual
|
||||
register: str_params_actual
|
||||
|
||||
- name: assert results of install service with free form parameters
|
||||
- name: assert results of install service with string form parameters
|
||||
assert:
|
||||
that:
|
||||
- free_params.changed == true
|
||||
- (free_params_actual.stdout|from_json).Exists == true
|
||||
- (free_params_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -v -Dcom.test.string=value "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (free_params_actual.stdout|from_json).Parameters.AppParameters == '-v -Dcom.test.string=value "C:\\with space\\\\"'
|
||||
- str_params.changed == true
|
||||
- (str_params_actual.stdout|from_json).Exists == true
|
||||
- (str_params_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -v -Dtest.str=value "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (str_params_actual.stdout|from_json).Parameters.AppParameters == '-v -Dtest.str=value "C:\\with space\\\\"'
|
||||
|
||||
- name: install service with free form parameters (idempotent)
|
||||
- name: install service with string form parameters (idempotent)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
app_parameters_free_form: '-v -Dcom.test.string=value "C:\with space\\"'
|
||||
arguments: '-v -Dtest.str=value "C:\with space\\"'
|
||||
state: present
|
||||
register: free_params_again
|
||||
register: str_params_again
|
||||
|
||||
- name: get result of install service with free form parameters (idempotent)
|
||||
- name: get result of install service with string form parameters (idempotent)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: free_params_again_actual
|
||||
register: str_params_again_actual
|
||||
|
||||
- name: assert results of install service with free form parameters (idempotent)
|
||||
- name: assert results of install service with string form parameters (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- free_params_again.changed == false
|
||||
- (free_params_again_actual.stdout|from_json).Exists == true
|
||||
- (free_params_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -v -Dcom.test.string=value "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (free_params_again_actual.stdout|from_json).Parameters.AppParameters == '-v -Dcom.test.string=value "C:\\with space\\\\"'
|
||||
- str_params_again.changed == false
|
||||
- (str_params_again_actual.stdout|from_json).Exists == true
|
||||
- (str_params_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -v -Dtest.str=value "C:\with space\\" (backslashes doubled for jinja)
|
||||
- (str_params_again_actual.stdout|from_json).Parameters.AppParameters == '-v -Dtest.str=value "C:\\with space\\\\"'
|
||||
|
||||
- name: install service with dict parameters
|
||||
# deprecated in 2.12
|
||||
- name: install service with dict-as-string parameters
|
||||
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
|
||||
register: mixed_params
|
||||
|
||||
- name: get result of install service with dict parameters
|
||||
# deprecated in 2.12
|
||||
- name: get result of install service with dict-as-string parameters
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: mixed_params_actual
|
||||
|
||||
- name: assert results of install service with dict parameters
|
||||
# deprecated in 2.12
|
||||
- name: assert results of install service with dict-as-string parameters
|
||||
assert:
|
||||
that:
|
||||
- mixed_params.changed == true
|
||||
|
@ -203,18 +275,21 @@
|
|||
# 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)
|
||||
# deprecated in 2.12
|
||||
- name: install service with dict-as-string 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
|
||||
register: mixed_params_again
|
||||
|
||||
- name: get result of install service with dict parameters (idempotent)
|
||||
# deprecated in 2.12
|
||||
- name: get result of install service with dict-as-string parameters (idempotent)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: mixed_params_again_actual
|
||||
|
||||
- name: assert results of install service with dict parameters (idempotent)
|
||||
# deprecated in 2.12
|
||||
- name: assert results of install service with dict-as-string parameters (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- mixed_params_again.changed == false
|
||||
|
@ -223,6 +298,81 @@
|
|||
# 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: install service with list of parameters
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
arguments:
|
||||
- -foo=bar
|
||||
- -day
|
||||
# Test non-string value
|
||||
- 14
|
||||
# Test if dot is not interpreted as separator (see #44079)
|
||||
- -file.out
|
||||
# Test if spaces are escaped
|
||||
- C:\with space\output.bat
|
||||
- -str
|
||||
# Test if quotes and backslashes are escaped
|
||||
- test"quotes\
|
||||
register: list_params
|
||||
|
||||
- name: get result of install service with list of parameters
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: list_params_actual
|
||||
|
||||
- name: assert results of install service with list of parameters
|
||||
assert:
|
||||
that:
|
||||
- list_params.changed == true
|
||||
- (list_params_actual.stdout|from_json).Exists == true
|
||||
- (list_params_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -foo=bar -day 14 -file.out "C:\with space\output.bat" -str "test\"quotes\\" (backslashes doubled for jinja)
|
||||
- (list_params_actual.stdout|from_json).Parameters.AppParameters == '-foo=bar -day 14 -file.out "C:\\with space\\output.bat" -str "test\\"quotes\\\\"'
|
||||
|
||||
- name: install service with list of parameters (idempotent)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
application: C:\Windows\System32\cmd.exe
|
||||
arguments:
|
||||
- -foo=bar
|
||||
- -day
|
||||
- 14
|
||||
- -file.out
|
||||
- C:\with space\output.bat
|
||||
- -str
|
||||
- test"quotes\
|
||||
register: list_params_again
|
||||
|
||||
- name: get result of install service with list of parameters (idempotent)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: list_params_again_actual
|
||||
|
||||
- name: assert results of install service with list of parameters (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- list_params_again.changed == false
|
||||
- (list_params_again_actual.stdout|from_json).Exists == true
|
||||
- (list_params_again_actual.stdout|from_json).Parameters.Application == "C:\Windows\System32\cmd.exe"
|
||||
# Expected value: -foo=bar -day 14 -file.out "C:\with space\output.bat" -str "test\"quotes\\" (backslashes doubled for jinja)
|
||||
- (list_params_again_actual.stdout|from_json).Parameters.AppParameters == '-foo=bar -day 14 -file.out "C:\\with space\\output.bat" -str "test\\"quotes\\\\"'
|
||||
|
||||
- name: remove service (check mode)
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
state: absent
|
||||
register: remove_service_check
|
||||
check_mode: yes
|
||||
|
||||
- name: get result of remove service (check mode)
|
||||
win_shell: '$service = ''{{ test_service_name }}''; {{ test_service_cmd }}'
|
||||
register: remove_service_check_actual
|
||||
|
||||
- name: assert results of remove service (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remove_service_check.changed == true
|
||||
- (remove_service_check_actual.stdout|from_json).Exists == true
|
||||
|
||||
- name: remove service
|
||||
win_nssm:
|
||||
name: '{{ test_service_name }}'
|
||||
|
|
|
@ -91,9 +91,6 @@ lib/ansible/modules/windows/win_iis_website.ps1 PSUseDeclaredVarsMoreThanAssignm
|
|||
lib/ansible/modules/windows/win_lineinfile.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_mapped_drive.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_msg.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_nssm.ps1 PSAvoidUsingCmdletAliases
|
||||
lib/ansible/modules/windows/win_nssm.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_nssm.ps1 PSUseApprovedVerbs
|
||||
lib/ansible/modules/windows/win_package.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_package.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_package.ps1 PSUseApprovedVerbs
|
||||
|
|
Loading…
Reference in a new issue