mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_robocopy: Small cleanup (#20515)
- Harmonizing the checkmode usage in windows modules - Simplify the $result object - Add parameter types
This commit is contained in:
parent
8d4246ca2f
commit
fc7d6a4cd5
1 changed files with 19 additions and 21 deletions
|
@ -19,20 +19,23 @@
|
||||||
# WANT_JSON
|
# WANT_JSON
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args -supports_check_mode $true
|
||||||
|
|
||||||
$result = New-Object psobject @{
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||||
recurse = $false
|
|
||||||
purge = $false
|
|
||||||
changed = $false
|
|
||||||
}
|
|
||||||
|
|
||||||
$src = Get-AnsibleParam -obj $params -name "src" -type "path" -failifempty $true
|
$src = Get-AnsibleParam -obj $params -name "src" -type "path" -failifempty $true
|
||||||
$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true
|
$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true
|
||||||
$purge = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "purge" -default $false)
|
$purge = Get-AnsibleParam -obj $params -name "purge" -type "bool" -default $false
|
||||||
$recurse = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "recurse" -default $false)
|
$recurse = Get-AnsibleParam -obj $params -name "recurse" -type "bool" -default $false
|
||||||
$flags = Get-AnsibleParam -obj $params -name "flags" -default $null
|
$flags = Get-AnsibleParam -obj $params -name "flags" -type "string" -default $null
|
||||||
$_ansible_check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -default $false
|
|
||||||
|
$result = @{
|
||||||
|
src = $src
|
||||||
|
dest = $dest
|
||||||
|
recurse = $recurse
|
||||||
|
purge = $purge
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
# Search for an Error Message
|
# Search for an Error Message
|
||||||
# Robocopy seems to display an error after 3 '-----' separator lines
|
# Robocopy seems to display an error after 3 '-----' separator lines
|
||||||
|
@ -68,10 +71,7 @@ if (-Not (Test-Path $src)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$robocopy_opts += $src
|
$robocopy_opts += $src
|
||||||
Set-Attr $result "src" $src
|
|
||||||
|
|
||||||
$robocopy_opts += $dest
|
$robocopy_opts += $dest
|
||||||
Set-Attr $result "dest" $dest
|
|
||||||
|
|
||||||
if ($flags -eq $null) {
|
if ($flags -eq $null) {
|
||||||
if ($purge) {
|
if ($purge) {
|
||||||
|
@ -88,13 +88,11 @@ Else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Attr $result "purge" $purge
|
$result.flags = $flags
|
||||||
Set-Attr $result "recurse" $recurse
|
|
||||||
Set-Attr $result "flags" $flags
|
|
||||||
|
|
||||||
$robocopy_output = ""
|
$robocopy_output = ""
|
||||||
$rc = 0
|
$rc = 0
|
||||||
If ($_ansible_check_mode -eq $true) {
|
If ($check_mode -eq $true) {
|
||||||
$robocopy_output = "Would have copied the contents of $src to $dest"
|
$robocopy_output = "Would have copied the contents of $src to $dest"
|
||||||
$rc = 0
|
$rc = 0
|
||||||
}
|
}
|
||||||
|
@ -109,8 +107,8 @@ Else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Attr $result "return_code" $rc
|
$result.return_code = $rc
|
||||||
Set-Attr $result "output" $robocopy_output
|
$result.output = $robocopy_output
|
||||||
|
|
||||||
$cmd_msg = "Success"
|
$cmd_msg = "Success"
|
||||||
$changed = $false
|
$changed = $false
|
||||||
|
@ -161,7 +159,7 @@ switch ($rc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Attr $result "msg" $cmd_msg
|
$result.msg = $cmd_msg
|
||||||
Set-Attr $result "changed" $changed
|
$result.changed = $changed
|
||||||
|
|
||||||
Exit-Json $result
|
Exit-Json $result
|
||||||
|
|
Loading…
Reference in a new issue