mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_shell: Implement option 'profile', allowing the user to control p… (#54299)
* win_shell: Implement option 'profile', allowing the user to control powershell profile sourcing before running a command * Set version_added to 2.8 * Make sure profile directory exists before writing profile file * Changes to make tests immutable and align with ps args
This commit is contained in:
parent
e152b277cf
commit
b62ab97685
3 changed files with 40 additions and 0 deletions
|
@ -47,6 +47,7 @@ $executable = Get-AnsibleParam -obj $params -name "executable" -type "path"
|
||||||
$creates = Get-AnsibleParam -obj $params -name "creates" -type "path"
|
$creates = Get-AnsibleParam -obj $params -name "creates" -type "path"
|
||||||
$removes = Get-AnsibleParam -obj $params -name "removes" -type "path"
|
$removes = Get-AnsibleParam -obj $params -name "removes" -type "path"
|
||||||
$stdin = Get-AnsibleParam -obj $params -name "stdin" -type "str"
|
$stdin = Get-AnsibleParam -obj $params -name "stdin" -type "str"
|
||||||
|
$no_profile = Get-AnsibleParam -obj $params -name "no_profile" -type "bool" -default $false
|
||||||
|
|
||||||
$raw_command_line = $raw_command_line.Trim()
|
$raw_command_line = $raw_command_line.Trim()
|
||||||
|
|
||||||
|
@ -78,6 +79,10 @@ If(-not $executable -or $executable -eq "powershell") {
|
||||||
} else {
|
} else {
|
||||||
$exec_args = "-noninteractive -encodedcommand $encoded_command"
|
$exec_args = "-noninteractive -encodedcommand $encoded_command"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($no_profile) {
|
||||||
|
$exec_args = "-noprofile $exec_args"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
# FUTURE: support arg translation from executable (or executable_args?) to process arguments for arbitrary interpreter?
|
# FUTURE: support arg translation from executable (or executable_args?) to process arguments for arbitrary interpreter?
|
||||||
|
|
|
@ -47,6 +47,13 @@ options:
|
||||||
- Set the stdin of the command directly to the specified value.
|
- Set the stdin of the command directly to the specified value.
|
||||||
type: str
|
type: str
|
||||||
version_added: '2.5'
|
version_added: '2.5'
|
||||||
|
no_profile:
|
||||||
|
description:
|
||||||
|
- Do not load the user profile before running a command. This is only valid
|
||||||
|
when using PowerShell as the executable.
|
||||||
|
type: bool
|
||||||
|
default: no
|
||||||
|
version_added: '2.8'
|
||||||
notes:
|
notes:
|
||||||
- If you want to run an executable securely and predictably, it may be
|
- If you want to run an executable securely and predictably, it may be
|
||||||
better to use the M(win_command) module instead. Best practices when writing
|
better to use the M(win_command) module instead. Best practices when writing
|
||||||
|
|
|
@ -257,3 +257,31 @@
|
||||||
- nonascii_output.stdout_lines|count == 1
|
- nonascii_output.stdout_lines|count == 1
|
||||||
- nonascii_output.stdout_lines[0] == 'über den Fußgängerübergang gehen'
|
- nonascii_output.stdout_lines[0] == 'über den Fußgängerübergang gehen'
|
||||||
- nonascii_output.stderr == ''
|
- nonascii_output.stderr == ''
|
||||||
|
|
||||||
|
- name: execute powershell without no_profile
|
||||||
|
win_shell: '[System.Environment]::CommandLine'
|
||||||
|
register: no_profile
|
||||||
|
|
||||||
|
- name: assert execute powershell with no_profile
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- no_profile is successful
|
||||||
|
- no_profile is changed
|
||||||
|
- no_profile.cmd == "[System.Environment]::CommandLine"
|
||||||
|
- no_profile.rc == 0
|
||||||
|
- no_profile.stdout is match ('^powershell.exe -noninteractive -encodedcommand')
|
||||||
|
|
||||||
|
- name: execute powershell with no_profile
|
||||||
|
win_shell: '[System.Environment]::CommandLine'
|
||||||
|
args:
|
||||||
|
no_profile: yes
|
||||||
|
register: no_profile
|
||||||
|
|
||||||
|
- name: assert execute powershell with no_profile
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- no_profile is successful
|
||||||
|
- no_profile is changed
|
||||||
|
- no_profile.cmd == "[System.Environment]::CommandLine"
|
||||||
|
- no_profile.rc == 0
|
||||||
|
- no_profile.stdout is match ('^powershell.exe -noprofile -noninteractive -encodedcommand')
|
||||||
|
|
Loading…
Reference in a new issue