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
e9b6aaf5
Commit
e9b6aaf5
authored
Nov 23, 2014
by
Chris Church
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PowerShell command line processing to handle parameters passed via splatting.
parent
11610946
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
4 deletions
+49
-4
lib/ansible/runner/connection_plugins/winrm.py
+1
-1
lib/ansible/runner/shell_plugins/powershell.py
+5
-3
test/integration/roles/test_win_script/defaults/main.yml
+5
-0
test/integration/roles/test_win_script/files/test_script_with_splatting.ps1
+6
-0
test/integration/roles/test_win_script/tasks/main.yml
+32
-0
No files found.
lib/ansible/runner/connection_plugins/winrm.py
View file @
e9b6aaf5
...
...
@@ -143,7 +143,7 @@ class Connection(object):
vvv
(
"EXEC
%
s"
%
cmd
,
host
=
self
.
host
)
# For script/raw support.
if
cmd_parts
and
cmd_parts
[
0
]
.
lower
()
.
endswith
(
'.ps1'
):
script
=
powershell
.
_build_file_cmd
(
cmd_parts
)
script
=
powershell
.
_build_file_cmd
(
cmd_parts
,
quote_args
=
False
)
cmd_parts
=
powershell
.
_encode_script
(
script
,
as_list
=
True
)
try
:
result
=
self
.
_winrm_exec
(
cmd_parts
[
0
],
cmd_parts
[
1
:],
from_exec
=
True
)
...
...
lib/ansible/runner/shell_plugins/powershell.py
View file @
e9b6aaf5
...
...
@@ -53,9 +53,11 @@ def _encode_script(script, as_list=False):
return
cmd_parts
return
' '
.
join
(
cmd_parts
)
def
_build_file_cmd
(
cmd_parts
):
def
_build_file_cmd
(
cmd_parts
,
quote_args
=
True
):
'''Build command line to run a file, given list of file name plus args.'''
return
' '
.
join
(
_common_args
+
[
'-ExecutionPolicy'
,
'Unrestricted'
,
'-File'
]
+
[
'"
%
s"'
%
x
for
x
in
cmd_parts
])
if
quote_args
:
cmd_parts
=
[
'"
%
s"'
%
x
for
x
in
cmd_parts
]
return
' '
.
join
([
'&'
]
+
cmd_parts
)
class
ShellModule
(
object
):
...
...
@@ -110,7 +112,7 @@ class ShellModule(object):
cmd_parts
=
shlex
.
split
(
cmd
,
posix
=
False
)
if
not
cmd_parts
[
0
]
.
lower
()
.
endswith
(
'.ps1'
):
cmd_parts
[
0
]
=
'
%
s.ps1'
%
cmd_parts
[
0
]
script
=
_build_file_cmd
(
cmd_parts
)
script
=
_build_file_cmd
(
cmd_parts
,
quote_args
=
False
)
if
rm_tmp
:
rm_tmp
=
_escape
(
rm_tmp
)
script
=
'
%
s; Remove-Item "
%
s" -Force -Recurse;'
%
(
script
,
rm_tmp
)
...
...
test/integration/roles/test_win_script/defaults/main.yml
0 → 100644
View file @
e9b6aaf5
---
# Parameters to pass to test scripts.
test_win_script_value
:
VaLuE
test_win_script_splat
:
"
@{This='THIS';
That='THAT';
Other='OTHER'}"
test/integration/roles/test_win_script/files/test_script_with_splatting.ps1
0 → 100644
View file @
e9b6aaf5
# Test script to make sure the Ansible script module works when arguments are
# passed via splatting (http://technet.microsoft.com/en-us/magazine/gg675931.aspx)
Write-Host
$args
.This
Write-Host
$args
.That
Write-Host
$args
.Other
test/integration/roles/test_win_script/tasks/main.yml
View file @
e9b6aaf5
...
...
@@ -46,6 +46,38 @@
-
"
not
test_script_with_args_result|failed"
-
"
test_script_with_args_result|changed"
-
name
:
run test script that takes parameters passed via splatting
script
:
test_script_with_splatting.ps1 "@{ This = 'this'; That = '{{ test_win_script_value }}'; Other = 'other'}"
register
:
test_script_with_splatting_result
-
name
:
check that script ran and received parameters via splatting
assert
:
that
:
-
"
test_script_with_splatting_result.rc
==
0"
-
"
test_script_with_splatting_result.stdout"
-
"
test_script_with_splatting_result.stdout_lines[0]
==
'this'"
-
"
test_script_with_splatting_result.stdout_lines[1]
==
test_win_script_value"
-
"
test_script_with_splatting_result.stdout_lines[2]
==
'other'"
-
"
not
test_script_with_splatting_result.stderr"
-
"
not
test_script_with_splatting_result|failed"
-
"
test_script_with_splatting_result|changed"
-
name
:
run test script that takes splatted parameters from a variable
script
:
test_script_with_splatting.ps1 {{ test_win_script_splat|quote }}
register
:
test_script_with_splatting2_result
-
name
:
check that script ran and received parameters via splatting from a variable
assert
:
that
:
-
"
test_script_with_splatting2_result.rc
==
0"
-
"
test_script_with_splatting2_result.stdout"
-
"
test_script_with_splatting2_result.stdout_lines[0]
==
'THIS'"
-
"
test_script_with_splatting2_result.stdout_lines[1]
==
'THAT'"
-
"
test_script_with_splatting2_result.stdout_lines[2]
==
'OTHER'"
-
"
not
test_script_with_splatting2_result.stderr"
-
"
not
test_script_with_splatting2_result|failed"
-
"
test_script_with_splatting2_result|changed"
-
name
:
run test script that has errors
script
:
test_script_with_errors.ps1
register
:
test_script_with_errors_result
...
...
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