Server IP : 85.214.239.14 / Your IP : 3.145.61.142 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/community/windows/plugins/modules/ |
Upload File : |
#!powershell # Copyright: (c) 2021, Kento Yagisawa <thel.vadam2485@gmail.com> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) #AnsibleRequires -CSharpUtil Ansible.Basic $spec = @{ options = @{ # Need to support \* which type='path' does not, the path is expanded further down. src = @{ type = 'str'; required = $true } dest = @{ type = 'path'; required = $true } } supports_check_mode = $true } $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) $src = [Environment]::ExpandEnvironmentVariables($module.Params.src) $dest = $module.Params.dest $srcFile = [System.IO.Path]::GetFileName($src) $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal $encoding = New-Object -TypeName System.Text.UTF8Encoding -ArgumentList $false $srcWildcard = $false # If the path ends with '\*' we want to include the dir contents and not the dir itself If ($src -match '\\\*$') { $srcWildcard = $true $src = $src.Substring(0, $src.Length - 2) } If (-not (Test-Path -LiteralPath $src)) { $module.FailJson("The source file or directory '$src' does not exist.") } If ($dest -notlike "*.zip") { $module.FailJson("The destination zip file path '$dest' need to be zip file path.") } If (Test-Path -LiteralPath $dest) { $module.Result.msg = "The destination zip file '$dest' already exists." $module.ExitJson() } # Check .NET v4.5 or later version exists or not try { Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop } catch { $module.FailJson(".NET Framework 4.5 or later version needs to be installed.", $_) } Function Compress-Zip($src, $dest) { # Disable using backslash for Zip path. This works for .NET 4.6.1 or later if ([object].Assembly.GetType("System.AppContext")) { [System.AppContext]::SetSwitch('Switch.System.IO.Compression.ZipFile.UseBackslash', $false) } If (-not $module.CheckMode) { If (Test-Path -LiteralPath $src -PathType Container) { [System.IO.Compression.ZipFile]::CreateFromDirectory($src, $dest, $compressionLevel, (-not $srcWildcard), $encoding) } Else { $zip = [System.IO.Compression.ZipFile]::Open($dest, 'Update') try { [void][System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $src, $srcFile, $compressionLevel) } finally { $zip.Dispose() } } } $module.Result.changed = $true } Compress-Zip -src $src -dest $dest $module.ExitJson()