-
-
Notifications
You must be signed in to change notification settings - Fork 782
Implement a WinRM runner #4169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a WinRM runner #4169
Conversation
|
Cool. Resolves #1636 |
Support for parameters and string escapingJust pushed support for pulling out named and positional parameters from the Also added string quoting/escaping to help in that effort. /opt/stackstorm/pack/default/actions/winrm_script.yaml---
description: "Run an arbitrary WinRM script"
enabled: true
name: winrm_script
entry_point: ps_test.ps1
pack: default
parameters:
p_bool:
type: boolean
default: true
p_integer:
type: integer
default: 3
p_number:
type: number
default: 12.34
p_str:
type: string
default: "test"
p_array:
type: array
default: ["a", "b", "c"]
p_obj:
type: object
default:
a: a_value
b: b_value
pos0:
type: string
position: 0
default: "pos arg 0"
pos1:
type: string
position: 1
default: "pos arg 1"
runner_type: "winrm-ps-script"/opt/stackstorm/pack/default/actions/ps_test.ps1[CmdletBinding()]
Param(
[bool]$p_bool,
[int]$p_integer,
[double]$p_number,
[string]$p_str,
[array]$p_array,
[hashtable]$p_obj,
[Parameter(Position=0)]
[string]$p_pos0,
[Parameter(Position=1)]
[string]$p_pos1
)
Write-Output "p_bool = $p_bool"
Write-Output "p_integer = $p_integer"
Write-Output "p_number = $p_number"
Write-Output "p_str = $p_str"
Write-Output "p_array = $($p_array | ConvertTo-Json -Compress)"
Write-Output "p_obj = $($p_obj | ConvertTo-Json -Compress)"
Write-Output "p_pos0 = $p_pos0"
Write-Output "p_pos1 = $p_pos1"Execution$ st2 run default.winrm_script host=hostname.domain.tld username=user@domain.tld password=xxx verify_ssl_cert=false p_str='"test this `$string"'
..
id: 5b1acbcf595497f1ade243e9
status: succeeded
parameters:
host: hostname@domain.tld
p_str: '"test this `$string"'
password: '********'
username: user@domain.tld
verify_ssl_cert: false
result:
failed: false
return_code: 0
stderr: ''
stdout: "p_bool = True
p_integer = 3
p_number = 12.34
p_str = "test this `$string"
p_array = ["a","b","c"]
p_obj = {"a":"a_value","b":"b_value"}
p_pos0 = pos arg 0
p_pos1 = pos arg 1
"
succeeded: true |
| required: true | ||
| type: string | ||
| kwarg_op: | ||
| default: - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this may need to be quoted, otherwise the runner fails to register with yaml.scanner.ScannerError: sequence entries are not allowed here
Seems to allow -- without quoting, but not -.
|
I realized through my testing that the I just pushed a change that converts over all of the runners to using the same Now, the After this change, the An additional change is necessary to |
|
New update:
|
|
For anyone interested in testing out the new runner. The steps for using it on an existing system are: After this you can create actions that use the new runners |
|
Nice work 👍 I will perform a more detailed review shortly. As far as testing goes - we definitely need some kind of end to end tests which spin up Windows VM and test the functionality end to end, the same as we do for other runners (inside st2tests, etc.). For that we will need to modify workflows in st2cd, st2ci repos and add new tests to st2tests repo. |
|
Thanks for great working on those changes 👍 I'm looking into it / testing it today :) |
| return session | ||
|
|
||
| def _winrm_get_command_output(self, protocol, shell_id, command_id): | ||
| # NOTE: this is copied from pywinrm because it doesn't support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's based on an existing code, it would be good to also include under what license that code is (looks like MIT in this case).
|
I performed some basic testing locally (using Python 2 and 3) and everything looks good 👍 I tagged this PR with v2.9.0 milestone. This means we will need to wait a bit before we can merge it. I believe @enykeev will start on the v2.8.0 release process soon. As soon as he unfreezes master for new changes I will merge this and work on the CI and all the related changes. As discussed on Slack - it would be great if you can also work on the documentation change - how it works, how to use it and how to configure it :) |
Kami
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to be merged once master is ready to accept changes for the v2.9.0 release.
|
Can you please look into the failing tests - I believe they just need to be updated to take into an account a new runner (orchestra). |
|
I reverted ``from st2common import version` change because it needs more work (see #4211 (comment) for details). This way I can continue with merging and testing those changes |
|
Merged - thanks! I will continue with merging and testing docs and st2tests PRs tomorrow. It took me way too long today to get this branch in sync and all the tests passing (mostly due to slow CI). |
Description
This is a runner that utilizes WinRM to connect to a remote Windows host for command and script execution. I've chosen to implement it using the
pywinrmlibrary (https://github.com/diyan/pywinrm) which seems to be the Python standard, used by tools like Ansible and Salt.The runner is fairly simplistic, only executing commands on a single host at a time (not multiple in parallel like SSH/remote_runner). Due to some limitations in the
pywinrmlibrary, some code needed to be copied over in order to support "standard" StackStorm features such as: environment variables, cwd, and timeouts. Ideally we will forkpywinrmand create a PR for these changes.It supports both command and script executions. Currently parameters are not passed to the scripts when executing (in the TODO list)
Examples
Here are some example actions and commands to show it's working so others can play around:
/opt/stackstorm/packs/default/winrm_cmd.yaml
/opt/stackstorm/packs/default/winrm_script.yaml
Testing winrm-ps-cmd
Simple test
This proves that bot the
envandcwdoptions workThis executes the following powershell script
/opt/stackstorm/packs/default/actions/ps_test.ps1TODO
corepack actions