mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_owner: Clean up and check-mode support (#21385)
* win_owner: Clean up and check-mode support Changes include: - Use Get-AnsibleParam with -type/-validateset - Replace $result PSObject with normal hash - Add check-mode support * Implemented -WhatIf:$check_mode support * Revert to original formatting
This commit is contained in:
parent
313a9d3845
commit
928880c639
2 changed files with 15 additions and 17 deletions
|
@ -81,15 +81,16 @@ Function UserSearch
|
|||
}
|
||||
}
|
||||
|
||||
$params = Parse-Args $args;
|
||||
$result = @{
|
||||
changed = $false
|
||||
}
|
||||
|
||||
$result = New-Object PSObject;
|
||||
Set-Attr $result "changed" $false;
|
||||
$params = Parse-Args $args -supports_check_mode $true
|
||||
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||
|
||||
$path = Get-Attr $params "path" -failifempty $true
|
||||
$user = Get-Attr $params "user" -failifempty $true
|
||||
$recurse = Get-Attr $params "recurse" "no" -validateSet "no","yes" -resultobj $result
|
||||
$recurse = $recurse | ConvertTo-Bool
|
||||
$path = Get-AnsibleParam -obj $params -name "path" -type "path" -failifempty $true
|
||||
$user = Get-AnsibleParam -obj $params -name "user" -type "str" -failifempty $true
|
||||
$recurse = Get-AnsibleParam -obj $params -name "recurse" -type "bool" -default "no" -validateset "no","yes" -resultobj $result
|
||||
|
||||
If (-Not (Test-Path -Path $path)) {
|
||||
Fail-Json $result "$path file or directory does not exist on the host"
|
||||
|
@ -97,7 +98,7 @@ If (-Not (Test-Path -Path $path)) {
|
|||
|
||||
# Test that the user/group is resolvable on the local machine
|
||||
$sid = UserSearch -AccountName ($user)
|
||||
if (!$sid)
|
||||
if (-not $sid)
|
||||
{
|
||||
Fail-Json $result "$user is not a valid user or group on the host machine or domain"
|
||||
}
|
||||
|
@ -110,9 +111,8 @@ Try {
|
|||
|
||||
If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) {
|
||||
$acl.setOwner($objUser)
|
||||
Set-Acl $file.FullName $acl
|
||||
|
||||
Set-Attr $result "changed" $true;
|
||||
Set-Acl -Path $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
If ($recurse) {
|
||||
|
@ -122,9 +122,8 @@ Try {
|
|||
|
||||
If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) {
|
||||
$acl.setOwner($objUser)
|
||||
Set-Acl $file.FullName $acl
|
||||
|
||||
Set-Attr $result "changed" $true;
|
||||
Set-Acl -Path $file.FullName -AclObject $acl -WhatIf:$check_mode
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ options:
|
|||
recurse:
|
||||
description:
|
||||
- Indicates if the owner should be changed recursively
|
||||
required: false
|
||||
choices:
|
||||
- no
|
||||
- yes
|
||||
|
|
Loading…
Reference in a new issue