mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_dsc - return warning from DSC invocation (#51927)
This commit is contained in:
parent
338ad565a7
commit
179cbb9891
4 changed files with 16 additions and 2 deletions
2
changelogs/fragments/win_dsc-warning.yaml
Normal file
2
changelogs/fragments/win_dsc-warning.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- win_dsc - Display the warnings produced by the DSC engine for better troubleshooting - https://github.com/ansible/ansible/issues/51543
|
|
@ -236,7 +236,11 @@ try
|
||||||
{
|
{
|
||||||
#Defined variables in strictmode
|
#Defined variables in strictmode
|
||||||
$TestError, $TestError = $null
|
$TestError, $TestError = $null
|
||||||
$TestResult = Invoke-DscResource @Config -Method Test -ModuleName $Module -ErrorVariable TestError -ErrorAction SilentlyContinue
|
$TestResult = Invoke-DscResource @Config -Method Test -ModuleName $Module -ErrorVariable TestError -ErrorAction SilentlyContinue -WarningVariable TestWarn
|
||||||
|
foreach ($warning in $TestWarn) {
|
||||||
|
Add-Warning -obj $result -message $warning.Message
|
||||||
|
}
|
||||||
|
|
||||||
if ($TestError)
|
if ($TestError)
|
||||||
{
|
{
|
||||||
throw ($TestError[0].Exception.Message)
|
throw ($TestError[0].Exception.Message)
|
||||||
|
@ -245,7 +249,10 @@ try
|
||||||
{
|
{
|
||||||
if ($check_mode -eq $False)
|
if ($check_mode -eq $False)
|
||||||
{
|
{
|
||||||
$SetResult = Invoke-DscResource -Method Set @Config -ModuleName $Module -ErrorVariable SetError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
|
$SetResult = Invoke-DscResource -Method Set @Config -ModuleName $Module -ErrorVariable SetError -ErrorAction SilentlyContinue -WarningVariable SetWarn
|
||||||
|
foreach ($warning in $SetWarn) {
|
||||||
|
Add-Warning -obj $result -message $warning.Message
|
||||||
|
}
|
||||||
if ($SetError -and ($SetResult -eq $null))
|
if ($SetError -and ($SetResult -eq $null))
|
||||||
{
|
{
|
||||||
#If SetError was filled, throw to exit out of the try/catch loop
|
#If SetError was filled, throw to exit out of the try/catch loop
|
||||||
|
|
|
@ -307,6 +307,9 @@
|
||||||
that:
|
that:
|
||||||
- test_dsc_custom is changed
|
- test_dsc_custom is changed
|
||||||
- test_dsc_custom_output.content|b64decode|strip_newline == test_dsc_custom_expected|strip_newline
|
- test_dsc_custom_output.content|b64decode|strip_newline == test_dsc_custom_expected|strip_newline
|
||||||
|
- test_dsc_custom.warnings | length == 2
|
||||||
|
- "'[[xTestResource]DirectResourceAccess] test warning' in test_dsc_custom.warnings[0]"
|
||||||
|
- "'[[xTestResource]DirectResourceAccess] set warning' in test_dsc_custom.warnings[1]"
|
||||||
|
|
||||||
- name: run custom DSC resource with version
|
- name: run custom DSC resource with version
|
||||||
win_dsc:
|
win_dsc:
|
||||||
|
|
|
@ -119,6 +119,7 @@ CimInstanceArrayParam:
|
||||||
}
|
}
|
||||||
New-Item -Path $Path -ItemType File > $null
|
New-Item -Path $Path -ItemType File > $null
|
||||||
Set-Content -Path $Path -Value $file_contents > $null
|
Set-Content -Path $Path -Value $file_contents > $null
|
||||||
|
Write-Warning -Message "set warning"
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Test-TargetResource
|
Function Test-TargetResource
|
||||||
|
@ -167,6 +168,7 @@ Function Test-TargetResource
|
||||||
[Microsoft.Management.Infrastructure.CimInstance[]]
|
[Microsoft.Management.Infrastructure.CimInstance[]]
|
||||||
$CimInstanceArrayParam
|
$CimInstanceArrayParam
|
||||||
)
|
)
|
||||||
|
Write-Warning -Message "test warning"
|
||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue