diff --git a/changelogs/fragments/57804-win_acl-no-longer-needs-SeSecurityPrivilege.yml b/changelogs/fragments/57804-win_acl-no-longer-needs-SeSecurityPrivilege.yml new file mode 100644 index 00000000000..4f210d4d6b8 --- /dev/null +++ b/changelogs/fragments/57804-win_acl-no-longer-needs-SeSecurityPrivilege.yml @@ -0,0 +1,2 @@ +bugfixes: + - win_acl - Fixed error when setting rights on directory for which inheritance from parent directory has been disabled. diff --git a/lib/ansible/modules/windows/win_acl.ps1 b/lib/ansible/modules/windows/win_acl.ps1 index 8fc344bfc16..e3c3813038d 100644 --- a/lib/ansible/modules/windows/win_acl.ps1 +++ b/lib/ansible/modules/windows/win_acl.ps1 @@ -176,7 +176,11 @@ Try { If ($state -eq "present" -And $match -eq $false) { Try { $objACL.AddAccessRule($objACE) - Set-ACL -LiteralPath $path -AclObject $objACL + If ($path_item.PSProvider.Name -eq "Registry") { + Set-ACL -LiteralPath $path -AclObject $objACL + } else { + (Get-Item -LiteralPath $path).SetAccessControl($objACL) + } $result.changed = $true } Catch { @@ -186,7 +190,11 @@ Try { ElseIf ($state -eq "absent" -And $match -eq $true) { Try { $objACL.RemoveAccessRule($objACE) - Set-ACL -LiteralPath $path -AclObject $objACL + If ($path_item.PSProvider.Name -eq "Registry") { + Set-ACL -LiteralPath $path -AclObject $objACL + } else { + (Get-Item -LiteralPath $path).SetAccessControl($objACL) + } $result.changed = $true } Catch {