From 371f9fa90d7bbbe6df2f194dd7f2fc8a43744fe1 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 24 Feb 2017 07:38:17 +0100 Subject: [PATCH] win_slurp: Small cleanup (#21363) * win_slurp: Small cleanup Included changes: - Rewriting the parameter handling (aliases and type) - Modified the $result hash for both Exit-Json and Fail-Json - Changed the Test-Path statement * Revert to original formatting --- lib/ansible/modules/windows/slurp.ps1 | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/ansible/modules/windows/slurp.ps1 b/lib/ansible/modules/windows/slurp.ps1 index 073acddead..0c8b85e1db 100644 --- a/lib/ansible/modules/windows/slurp.ps1 +++ b/lib/ansible/modules/windows/slurp.ps1 @@ -17,30 +17,25 @@ # WANT_JSON # POWERSHELL_COMMON -$params = Parse-Args $args $true; +$params = Parse-Args $args -supports_check_mode $true; +$src = Get-AnsibleParam -obj $params -name "src" -type "path" -aliases "path" -failifempty $true; -$src = Get-Attr $params "src" (Get-Attr $params "path" $FALSE); -If (-not $src) -{ - Fail-Json (New-Object psobject) "missing required argument: src"; +$result = @{ + changed = $false; } -If (Test-Path -PathType Leaf $src) +If (Test-Path -Path $src -PathType Leaf) { $bytes = [System.IO.File]::ReadAllBytes($src); - $content = [System.Convert]::ToBase64String($bytes); - $result = New-Object psobject @{ - changed = $false - encoding = "base64" - content = $content - }; + $result.content = [System.Convert]::ToBase64String($bytes); + $result.encoding = "base64"; Exit-Json $result; } -ElseIf (Test-Path -PathType Container $src) +ElseIf (Test-Path -Path $src -PathType Container) { - Fail-Json (New-Object psobject) ("is a directory: " + $src); + Fail-Json $result "Path $src is a directory"; } Else { - Fail-Json (New-Object psobject) ("file not found: " + $src); + Fail-Json $result "Path $src is not found"; }