1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix win_environment: strict-mode fix for 'value' (#2404)

This commit is contained in:
Andrea Scarpino 2016-06-15 20:26:03 +02:00 committed by Matt Clay
parent 89d0ff1f17
commit 5bec8ad321

View file

@ -20,37 +20,18 @@
# POWERSHELL_COMMON # POWERSHELL_COMMON
$params = Parse-Args $args; $params = Parse-Args $args;
$state = Get-Attr $params "state" $null; $state = Get-AnsibleParam -obj $params -name "state" -default "present" -validateSet "present","absent"
$result = New-Object PSObject; $name = Get-AnsibleParam -obj $params -name "name" -failifempty $true
Set-Attr $result "changed" $false; $level = Get-AnsibleParam -obj $params -name "level" -validateSet "machine","process","user" -failifempty $true
$value = Get-AnsibleParam -obj $params -name "value"
If ($state) { If ($level) {
$state = $state.ToString().ToLower() $level = $level.ToString().ToLower()
If (($state -ne 'present') -and ($state -ne 'absent') ) {
Fail-Json $result "state is '$state'; must be 'present', or 'absent'"
}
} else {
$state = 'present'
}
If ($params.name)
{
$name = $params.name
} else {
Fail-Json $result "missing required argument: name"
}
$value = $params.value
If ($params.level) {
$level = $params.level.ToString().ToLower()
If (( $level -ne 'machine') -and ( $level -ne 'user' ) -and ( $level -ne 'process')) {
Fail-Json $result "level is '$level'; must be 'machine', 'user', or 'process'"
}
} }
$before_value = [Environment]::GetEnvironmentVariable($name, $level) $before_value = [Environment]::GetEnvironmentVariable($name, $level)
$state = $state.ToString().ToLower()
if ($state -eq "present" ) { if ($state -eq "present" ) {
[Environment]::SetEnvironmentVariable($name, $value, $level) [Environment]::SetEnvironmentVariable($name, $value, $level)
} Elseif ($state -eq "absent") { } Elseif ($state -eq "absent") {
@ -59,6 +40,8 @@ if ($state -eq "present" ) {
$after_value = [Environment]::GetEnvironmentVariable($name, $level) $after_value = [Environment]::GetEnvironmentVariable($name, $level)
$result = New-Object PSObject;
Set-Attr $result "changed" $false;
Set-Attr $result "name" $name; Set-Attr $result "name" $name;
Set-Attr $result "before_value" $before_value; Set-Attr $result "before_value" $before_value;
Set-Attr $result "value" $after_value; Set-Attr $result "value" $after_value;