mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.7 KiB
YAML
77 lines
2.7 KiB
YAML
---
|
|
- name: collect the coverage files from the Windows host
|
|
hosts: windows
|
|
gather_facts: no
|
|
tasks:
|
|
- name: make sure all vars have been set
|
|
assert:
|
|
that:
|
|
- local_temp_path is defined
|
|
- remote_temp_path is defined
|
|
|
|
- name: zip up all coverage files in the
|
|
win_shell: |
|
|
$coverage_dir = '{{ remote_temp_path }}'
|
|
$zip_file = Join-Path -Path $coverage_dir -ChildPath 'coverage.zip'
|
|
if (Test-Path -LiteralPath $zip_file) {
|
|
Remove-Item -LiteralPath $zip_file -Force
|
|
}
|
|
|
|
$coverage_files = Get-ChildItem -LiteralPath $coverage_dir -Include '*=coverage*' -File
|
|
|
|
$legacy = $false
|
|
try {
|
|
# Requires .NET 4.5+ which isn't present on older WIndows versions. Remove once 2008/R2 is EOL.
|
|
# We also can't use the Shell.Application as it will fail on GUI-less servers (Server Core).
|
|
Add-Type -AssemblyName System.IO.Compression -ErrorAction Stop > $null
|
|
} catch {
|
|
$legacy = $true
|
|
}
|
|
|
|
if ($legacy) {
|
|
New-Item -Path $zip_file -ItemType File > $null
|
|
$shell = New-Object -ComObject Shell.Application
|
|
$zip = $shell.Namespace($zip_file)
|
|
foreach ($file in $coverage_files) {
|
|
$zip.CopyHere($file.FullName)
|
|
}
|
|
} else {
|
|
$fs = New-Object -TypeName System.IO.FileStream -ArgumentList $zip_file, 'CreateNew'
|
|
try {
|
|
$archive = New-Object -TypeName System.IO.Compression.ZipArchive -ArgumentList @(
|
|
$fs,
|
|
[System.IO.Compression.ZipArchiveMode]::Create
|
|
)
|
|
try {
|
|
foreach ($file in $coverage_files) {
|
|
$archive_entry = $archive.CreateEntry($file.Name, 'Optimal')
|
|
$entry_fs = $archive_entry.Open()
|
|
try {
|
|
$file_fs = [System.IO.File]::OpenRead($file.FullName)
|
|
try {
|
|
$file_fs.CopyTo($entry_fs)
|
|
} finally {
|
|
$file_fs.Dispose()
|
|
}
|
|
} finally {
|
|
$entry_fs.Dispose()
|
|
}
|
|
}
|
|
} finally {
|
|
$archive.Dispose()
|
|
}
|
|
} finally {
|
|
$fs.Dispose()
|
|
}
|
|
}
|
|
|
|
- name: fetch coverage zip file to localhost
|
|
fetch:
|
|
src: '{{ remote_temp_path }}\coverage.zip'
|
|
dest: '{{ local_temp_path }}/coverage-{{ inventory_hostname }}.zip'
|
|
flat: yes
|
|
|
|
- name: remove the temporary coverage directory
|
|
win_file:
|
|
path: '{{ remote_temp_path }}'
|
|
state: absent |