Server IP : 85.214.239.14 / Your IP : 3.148.112.15 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/ansible/windows/plugins/modules/ |
Upload File : |
#!powershell # Copyright: (c) 2015, Hans-Joachim Kliemeck <git@kliemeck.de> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) #Requires -Module Ansible.ModuleUtils.Legacy #Requires -Module Ansible.ModuleUtils.SID $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-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 $false -resultobj $result If (-Not (Test-Path -LiteralPath $path)) { Fail-Json $result "$path file or directory does not exist on the host" } # Test that the user/group is resolvable on the local machine $sid = Convert-ToSID -account_name $user if (!$sid) { Fail-Json $result "$user is not a valid user or group on the host machine or domain" } Try { $objUser = New-Object System.Security.Principal.SecurityIdentifier($sid) $file = Get-Item -LiteralPath $path $acl = Get-Acl -LiteralPath $file.FullName If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) { $acl.setOwner($objUser) Set-Acl -LiteralPath $file.FullName -AclObject $acl -WhatIf:$check_mode $result.changed = $true } If ($recurse -and $file -is [System.IO.DirectoryInfo]) { # Get-ChildItem falls flat on pre PSv5 when dealing with complex path chars $files = $file.EnumerateFileSystemInfos("*", [System.IO.SearchOption]::AllDirectories) ForEach ($file in $files) { $acl = Get-Acl -LiteralPath $file.FullName If ($acl.getOwner([System.Security.Principal.SecurityIdentifier]) -ne $objUser) { $acl.setOwner($objUser) Set-Acl -LiteralPath $file.FullName -AclObject $acl -WhatIf:$check_mode $result.changed = $true } } } } Catch { Fail-Json $result "an error occurred when attempting to change owner on $path for $($user): $($_.Exception.Message)" } Exit-Json $result