mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
test: optimize win_psmodule tests (#53431)
This commit is contained in:
parent
57f706e5a0
commit
830a11dd38
23 changed files with 841 additions and 1235 deletions
2
changelogs/fragments/win_psmodule-repository.yaml
Normal file
2
changelogs/fragments/win_psmodule-repository.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- win_psmodule - The ``url`` parameter is deprecated and will be removed in Ansible 2.12. Use the ``win_psrepository`` module to manage repositories instead
|
|
@ -291,6 +291,7 @@ Function Install-Repository {
|
|||
[string]$Url,
|
||||
[bool]$CheckMode
|
||||
)
|
||||
Add-DeprecationWarning -obj $result -message "Adding a repo with this module is deprecated, the repository parameter should only be used to select a repo. Use win_psrepository to manage repos" -version 2.12
|
||||
# Install NuGet provider if needed.
|
||||
Install-NugetProvider -CheckMode $CheckMode
|
||||
|
||||
|
@ -318,6 +319,7 @@ Function Remove-Repository{
|
|||
[string]$Name,
|
||||
[bool]$CheckMode
|
||||
)
|
||||
Add-DeprecationWarning -obj $result -message "Removing a repo with this module is deprecated, use win_psrepository to manage repos" -version 2.12
|
||||
|
||||
$Repo = (Get-PSRepository).Name
|
||||
|
||||
|
|
|
@ -70,11 +70,13 @@ options:
|
|||
version_added: "2.8"
|
||||
repository:
|
||||
description:
|
||||
- Name of the custom repository to register or use.
|
||||
- Name of the custom repository to use.
|
||||
type: str
|
||||
url:
|
||||
description:
|
||||
- URL of the custom repository to register.
|
||||
- This option is deprecated and will be removed in Ansible 2.12. Use the
|
||||
M(win_psrepository) module instead.
|
||||
type: str
|
||||
notes:
|
||||
- PowerShell modules needed
|
||||
|
|
2
test/integration/targets/setup_win_psget/meta/main.yml
Normal file
2
test/integration/targets/setup_win_psget/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_remote_tmp_dir
|
87
test/integration/targets/setup_win_psget/tasks/main.yml
Normal file
87
test/integration/targets/setup_win_psget/tasks/main.yml
Normal file
|
@ -0,0 +1,87 @@
|
|||
# Installs PackageManagement and PowerShellGet to the required versions for testing
|
||||
---
|
||||
- name: check if PackageManagement has been installed
|
||||
win_shell: if (Get-Command -Name Install-Module -ErrorAction SilentlyContinue) { $true } else { $false }
|
||||
changed_when: False
|
||||
register: module_installed
|
||||
|
||||
- name: install PackageManagement and PowerShellGet
|
||||
when: not module_installed.stdout | trim | bool
|
||||
block:
|
||||
- name: install PackageManagement
|
||||
win_package:
|
||||
path: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_win_psget/PackageManagement_x64.msi
|
||||
product_id: '{57E5A8BB-41EB-4F09-B332-B535C5954A28}'
|
||||
state: present
|
||||
|
||||
- name: create the required folder
|
||||
win_file:
|
||||
path: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208
|
||||
state: directory
|
||||
|
||||
- name: download nuget provider dll
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_win_psget/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll
|
||||
dest: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll
|
||||
|
||||
- name: get version and install location of PackageManagement and PowerShellGet
|
||||
win_shell: |
|
||||
$info = @{}
|
||||
$modules = Get-Module -ListAvailable | Where-Object {
|
||||
($_.Name -eq "PackageManagement" -and $_.Version -lt "1.1.7") -or ($_.Name -eq "PowerShellGet" -and $_.Version -lt "1.6.0")
|
||||
} | ForEach-Object {
|
||||
$module_info = @{}
|
||||
if ([System.IO.Path]::GetFileName($_.ModuleBase) -eq $_.Name) {
|
||||
$module_info.remove_path = $_.ModuleBase
|
||||
$module_info.install_path = $_.ModuleBase
|
||||
} else {
|
||||
$module_version = switch($_.Name) {
|
||||
PackageManagement { "1.1.7.0" }
|
||||
PowerShellGet { "1.6.0" }
|
||||
}
|
||||
$module_info.remove_path = ""
|
||||
$module_info.install_path = ([System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.ModuleBase), $module_version))
|
||||
}
|
||||
$info.($_.Name) = $module_info
|
||||
}
|
||||
|
||||
ConvertTo-Json -InputObject $info -Compress
|
||||
changed_when: False
|
||||
register: installed_modules
|
||||
|
||||
- name: register installed_modules info
|
||||
set_fact:
|
||||
installed_modules: '{{ installed_modules.stdout | trim | from_json }}'
|
||||
|
||||
- name: update the PackageManagement and PowerShellGet versions
|
||||
when: installed_modules.keys() | list | length > 0
|
||||
block:
|
||||
- name: download newer PackageManagement and PowerShellGet nupkg
|
||||
win_get_url:
|
||||
url: '{{ item.url }}'
|
||||
dest: '{{ remote_tmp_dir }}\{{ item.name }}.zip' # .zip is required for win_unzip
|
||||
when: item.name in installed_modules
|
||||
loop:
|
||||
- name: PackageManagement
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_win_psget/packagemanagement.1.1.7.nupkg
|
||||
- name: PowerShellGet
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_win_psget/powershellget.1.6.0.nupkg
|
||||
|
||||
- name: remove the old versions of PackageManagement and PowerShellGet
|
||||
win_file:
|
||||
path: '{{ item.value.remove_path }}'
|
||||
state: absent
|
||||
# This isn't necessary on 2016+ as packages are installed in a version specific dir
|
||||
when: item.value.remove_path != ""
|
||||
with_dict: '{{ installed_modules }}'
|
||||
|
||||
- name: extract new modules to correct location
|
||||
win_unzip:
|
||||
src: '{{ remote_tmp_dir }}\{{ item.name }}.zip'
|
||||
dest: '{{ item.path }}'
|
||||
when: item.path != ""
|
||||
loop:
|
||||
- name: PackageManagement
|
||||
path: '{{ installed_modules.PackageManagement.install_path | default("") }}'
|
||||
- name: PowerShellGet
|
||||
path: '{{ installed_modules.PowerShellGet.install_path | default("") }}'
|
|
@ -1,27 +0,0 @@
|
|||
---
|
||||
powershell_module: powershell-yaml
|
||||
wrong_module: powershell_yaml
|
||||
allow_clobber_module: PowerShellCookbook
|
||||
fake_repo_name: FakeRepo
|
||||
custom_repo_path: C:\_repo
|
||||
custom_repo_name: PSRegisterRepo
|
||||
|
||||
powershell_module_required_version: 0.3.4
|
||||
powershell_module_maximum_version_request: 0.2.2
|
||||
powershell_module_maximum_version_result: 0.2
|
||||
powershell_module_ultra_high_version: 15.0.0
|
||||
powershell_module_ultra_low_version: 0.0.1
|
||||
|
||||
skip_publisher_check_module: Pester
|
||||
|
||||
powershell_module_2: Pester
|
||||
powershell_module_2_minimum_version_request: 3.1.2
|
||||
powershell_module_2_maximum_version_request: 3.3.0
|
||||
powershell_module_2_minimum_maximum_version_result: 3.2.0
|
||||
|
||||
allow_prerelease_module: Pester
|
||||
allow_prerelease_version: 4.4.0-beta2
|
||||
|
||||
myget_powershell_module: xActiveDirectory
|
||||
myget_repository_name: My Get
|
||||
myget_repository_url: https://www.myget.org/F/powershellgetdemo/api/v2
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>--- NAME ---</id>
|
||||
<version>--- VERSION ---</version>
|
||||
<authors>Ansible</authors>
|
||||
<owners>Ansible</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Test for Ansible win_ps* modules</description>
|
||||
<releaseNotes></releaseNotes>
|
||||
<copyright>Copyright (c) 2019 Ansible, licensed under MIT.</copyright>
|
||||
<tags>PSModule PSIncludes_Function PSFunction_--- FUNCTION --- PSCommand_--- FUNCTION ---</tags>
|
||||
</metadata>
|
||||
</package>
|
|
@ -0,0 +1,17 @@
|
|||
@{
|
||||
RootModule = '--- NAME ---.psm1'
|
||||
ModuleVersion = '--- VERSION ---'
|
||||
GUID = '--- GUID ---'
|
||||
Author = 'Ansible'
|
||||
Copyright = 'Copyright (c) 2019 Ansible, licensed under MIT.'
|
||||
Description = "Test for Ansible win_ps* modules"
|
||||
PowerShellVersion = '3.0'
|
||||
FunctionsToExport = @(
|
||||
"--- FUNCTION ---"
|
||||
)
|
||||
PrivateData = @{
|
||||
PSData = @{
|
||||
--- PS_DATA ---
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
Function --- FUNCTION --- {
|
||||
return [PSCustomObject]@{
|
||||
Name = "--- NAME ---"
|
||||
Version = "--- VERSION ---"
|
||||
Repo = "--- REPO ---"
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function --- FUNCTION ---
|
||||
|
9
test/integration/targets/win_psmodule/files/openssl.conf
Normal file
9
test/integration/targets/win_psmodule/files/openssl.conf
Normal file
|
@ -0,0 +1,9 @@
|
|||
distinguished_name = req_distinguished_name
|
||||
|
||||
[req_distinguished_name]
|
||||
|
||||
[req_sign]
|
||||
subjectKeyIdentifier=hash
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = digitalSignature
|
||||
extendedKeyUsage = codeSigning
|
19
test/integration/targets/win_psmodule/files/setup_certs.sh
Normal file
19
test/integration/targets/win_psmodule/files/setup_certs.sh
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Generate key used for CA cert
|
||||
openssl genrsa -aes256 -out ca.key -passout pass:password 2048
|
||||
|
||||
# Generate CA certificate
|
||||
openssl req -new -x509 -days 365 -key ca.key -out ca.pem -subj "/CN=Ansible Root" -passin pass:password
|
||||
|
||||
# Generate key used for signing cert
|
||||
openssl genrsa -aes256 -out sign.key -passout pass:password 2048
|
||||
|
||||
# Generate CSR for signing cert that includes CodeSiging extension
|
||||
openssl req -new -key sign.key -out sign.csr -subj "/CN=Ansible Sign" -config openssl.conf -reqexts req_sign -passin pass:password
|
||||
|
||||
# Generate signing certificate
|
||||
openssl x509 -req -in sign.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out sign.pem -days 365 -extfile openssl.conf -extensions req_sign -passin pass:password
|
||||
|
||||
# Create pfx that includes signing cert and cert with the pass 'password'
|
||||
openssl pkcs12 -export -out sign.pfx -inkey sign.key -in sign.pem -passin pass:password -passout pass:password
|
|
@ -0,0 +1,81 @@
|
|||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$template_path = $args[0]
|
||||
$template_manifest = Join-Path -Path $template_path -ChildPath template.psd1
|
||||
$template_script = Join-Path -Path $template_path -ChildPath template.psm1
|
||||
$template_nuspec = Join-Path -Path $template_path -ChildPath template.nuspec
|
||||
$nuget_exe = Join-Path -Path $template_path -ChildPath nuget.exe
|
||||
$sign_cert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @(
|
||||
(Join-Path -Path $template_path -ChildPath sign.pfx),
|
||||
'password',
|
||||
# We need to use MachineKeySet so we can load the pfx without using become
|
||||
# EphemeralKeySet would be better but it is only available starting with .NET 4.7.2
|
||||
[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet
|
||||
)
|
||||
|
||||
$packages = @(
|
||||
@{ name = "ansible-test1"; version = "1.0.0"; repo = "PSRepo 1"; function = "Get-AnsibleTest1" },
|
||||
@{ name = "ansible-test1"; version = "1.0.5"; repo = "PSRepo 1"; function = "Get-AnsibleTest1" },
|
||||
@{ name = "ansible-test1"; version = "1.1.0"; repo = "PSRepo 1"; function = "Get-AnsibleTest1" },
|
||||
@{ name = "ansible-test2"; version = "1.0.0"; repo = "PSRepo 1"; function = "Get-AnsibleTest2" },
|
||||
@{ name = "ansible-test2"; version = "1.0.0"; repo = "PSRepo 2"; function = "Get-AnsibleTest2" },
|
||||
@{ name = "ansible-test2"; version = "1.0.1"; repo = "PSRepo 1"; function = "Get-AnsibleTest2"; signed = $false },
|
||||
@{ name = "ansible-test2"; version = "1.1.0"; prerelease = "beta1"; repo = "PSRepo 1"; function = "Get-AnsibleTest2" },
|
||||
@{ name = "ansible-clobber"; version = "0.1.0"; repo = "PSRepo 1"; function = "Enable-PSTrace" }
|
||||
)
|
||||
|
||||
foreach ($package in $packages) {
|
||||
$tmp_dir = Join-Path -Path $template_path -ChildPath $package.name
|
||||
if (Test-Path -Path $tmp_dir) {
|
||||
Remove-Item -Path $tmp_dir -Force -Recurse
|
||||
}
|
||||
New-Item -Path $tmp_dir -ItemType Directory > $null
|
||||
|
||||
try {
|
||||
if ($package.ContainsKey("prerelease")) {
|
||||
$ps_data = "Prerelease = '$($package.prerelease)'"
|
||||
$nuget_version = "$($package.version)-$($package.prerelease)"
|
||||
} else {
|
||||
$ps_data = ""
|
||||
$nuget_version = $package.version
|
||||
}
|
||||
|
||||
$manifest = [System.IO.File]::ReadAllText($template_manifest)
|
||||
$manifest = $manifest.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $package.version)
|
||||
$manifest = $manifest.Replace('--- GUID ---', [Guid]::NewGuid()).Replace('--- FUNCTION ---', $package.function)
|
||||
|
||||
$manifest = $manifest.Replace('--- PS_DATA ---', $ps_data)
|
||||
$manifest_path = Join-Path -Path $tmp_dir -ChildPath "$($package.name).psd1"
|
||||
Set-Content -Path $manifest_path -Value $manifest
|
||||
|
||||
$script = [System.IO.File]::ReadAllText($template_script)
|
||||
$script = $script.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $package.version)
|
||||
$script = $script.Replace('--- REPO ---', $package.repo).Replace('--- FUNCTION ---', $package.function)
|
||||
$script_path = Join-Path -Path $tmp_dir -ChildPath "$($package.name).psm1"
|
||||
Set-Content -Path $script_path -Value $script
|
||||
|
||||
$signed = if ($package.ContainsKey("signed")) { $package.signed } else { $true }
|
||||
if ($signed) {
|
||||
Set-AuthenticodeSignature -Certificate $sign_cert -LiteralPath $manifest_path > $null
|
||||
Set-AuthenticodeSignature -Certificate $sign_cert -LiteralPath $script_path > $null
|
||||
}
|
||||
|
||||
# We should just be able to use Publish-Module but it fails when running over WinRM for older hosts and become
|
||||
# does not fix this. It fails to respond to nuget.exe push errors when it canno find the .nupkg file. We will
|
||||
# just manually do that ourselves. This also has the added benefit of being a lot quicker than Publish-Module
|
||||
# which seems to take forever to publish the module.
|
||||
$nuspec = [System.IO.File]::ReadAllText($template_nuspec)
|
||||
$nuspec = $nuspec.Replace('--- NAME ---', $package.name).Replace('--- VERSION ---', $nuget_version)
|
||||
$nuspec = $nuspec.Replace('--- FUNCTION ---', $package.function)
|
||||
Set-Content -Path (Join-Path -Path $tmp_dir -ChildPath "$($package.name).nuspec") -Value $nuspec
|
||||
|
||||
&$nuget_exe pack "$tmp_dir\$($package.name).nuspec" -outputdirectory $tmp_dir
|
||||
|
||||
$repo_path = Join-Path -Path $template_path -ChildPath $package.repo
|
||||
$nupkg_filename = "$($package.name).$($nuget_version).nupkg"
|
||||
Copy-Item -Path (Join-Path -Path $tmp_dir -ChildPath $nupkg_filename) `
|
||||
-Destination (Join-Path -Path $repo_path -ChildPath $nupkg_filename)
|
||||
} finally {
|
||||
Remove-Item -Path $tmp_dir -Force -Recurse
|
||||
}
|
||||
}
|
34
test/integration/targets/win_psmodule/handlers/main.yml
Normal file
34
test/integration/targets/win_psmodule/handlers/main.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
- name: re-add PSGallery repository
|
||||
win_shell: Register-PSRepository -Default -InstallationPolicy Untrusted
|
||||
|
||||
- name: remove registered repos
|
||||
win_psrepository:
|
||||
name: '{{ item }}'
|
||||
state: absent
|
||||
loop:
|
||||
- PSRepo 1
|
||||
- PSRepo 2
|
||||
|
||||
- name: remove CA cert from trusted root store
|
||||
win_certificate_store:
|
||||
thumbprint: '{{ ca_cert_import.thumbprints[0] }}'
|
||||
store_location: LocalMachine
|
||||
store_name: Root
|
||||
state: absent
|
||||
|
||||
- name: remove signing key from trusted publisher store
|
||||
win_certificate_store:
|
||||
thumbprint: '{{ sign_cert_import.thumbprints[0] }}'
|
||||
store_location: LocalMachine
|
||||
store_name: TrustedPublisher
|
||||
state: absent
|
||||
|
||||
- name: remove test packages
|
||||
win_psmodule:
|
||||
name: '{{ item }}'
|
||||
state: absent
|
||||
loop:
|
||||
- ansible-test1
|
||||
- ansible-test2
|
||||
- ansible-clobber
|
|
@ -1,2 +1,3 @@
|
|||
dependencies:
|
||||
- prepare_win_tests
|
||||
- setup_remote_tmp_dir
|
||||
- setup_win_psget
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
# This file is part of Ansible
|
||||
|
||||
# test code for the win_psmodule module when using winrm connection
|
||||
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
---
|
||||
- name: uninstall any versions of modules used for tests
|
||||
win_shell: |
|
||||
$ModulesToUninstall = @('powershell-yaml', 'Pester', 'PowerShellCookbook', 'xActiveDirectory')
|
||||
ForEach ( $ModuleToUninstall in $ModulesToUninstall ) {
|
||||
Uninstall-Module $ModuleToUninstall -AllVersions -Force -ErrorAction Ignore
|
||||
}
|
||||
changed_when: false
|
||||
|
||||
- name: unregister the custom repo
|
||||
win_psrepository:
|
||||
name: "{{ item | quote }}"
|
||||
state: absent
|
||||
changed_when: false
|
||||
with_items:
|
||||
- "{{ custom_repo_name }}"
|
||||
- "{{ myget_repository_name }}"
|
||||
|
||||
- name: remove the custom repo folder
|
||||
win_file:
|
||||
path: "{{ custom_repo_path }}"
|
||||
state: absent
|
||||
changed_when: false
|
||||
ignore_errors: yes
|
|
@ -1,95 +1,454 @@
|
|||
# This file is part of Ansible
|
||||
|
||||
# test code for the win_psmodule module when using winrm connection
|
||||
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net>
|
||||
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
---
|
||||
- name: setup test repos and modules
|
||||
import_tasks: setup.yml
|
||||
|
||||
- name: get PowerShell version
|
||||
win_shell: '$PSVersionTable.PSVersion.Major'
|
||||
changed_when: false
|
||||
register: powershell_major_version
|
||||
# Remove the below task in Ansible 2.12
|
||||
- name: ensure warning is fired when adding a repo
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
repository: some repo
|
||||
url: '{{ remote_tmp_dir }}'
|
||||
state: present
|
||||
register: dep_repo_add
|
||||
ignore_errors: yes # will fail because this repo doesn't actually have this module
|
||||
check_mode: yes
|
||||
|
||||
- name: update PackageManagement and PowerShellGet when PowerShell < 5.0
|
||||
when: powershell_major_version.stdout | int < 5
|
||||
block:
|
||||
- name: download PackageManagement
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/PackageManagement_x64.msi
|
||||
dest: '{{ win_output_dir }}\PackageManagement_x64.msi'
|
||||
- name: assert warning is fired when adding a repo
|
||||
assert:
|
||||
that:
|
||||
- dep_repo_add is changed
|
||||
- dep_repo_add.deprecations|length == 1
|
||||
- dep_repo_add.deprecations[0].msg == 'Adding a repo with this module is deprecated, the repository parameter should only be used to select a repo. Use win_psrepository to manage repos'
|
||||
- dep_repo_add.deprecations[0].version == 2.12
|
||||
|
||||
- name: install PackageManagement
|
||||
win_package:
|
||||
path: '{{ win_output_dir }}\PackageManagement_x64.msi'
|
||||
state: present
|
||||
- name: install package (check mode)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: present
|
||||
register: install_check
|
||||
check_mode: yes
|
||||
|
||||
- name: create the required folder
|
||||
win_file:
|
||||
path: 'C:\Program Files\PackageManagement\ProviderAssemblies'
|
||||
state: directory
|
||||
- name: get result of install package (check mode)
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test1 | Measure-Object).Count
|
||||
register: install_actual_check
|
||||
|
||||
- name: download nuget
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/nuget.exe
|
||||
dest: 'C:\Program Files\PackageManagement\ProviderAssemblies\NuGet-anycpu.exe'
|
||||
- name: assert install package (check mode)
|
||||
assert:
|
||||
that:
|
||||
- install_check is changed
|
||||
- install_actual_check.stdout | trim | int == 0
|
||||
|
||||
- name: update NuGet provider
|
||||
win_shell: 'Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies'
|
||||
- name: install package
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: present
|
||||
register: install
|
||||
|
||||
- name: download and save the nevest version of the PackageManagement module from PowerShell Gallery
|
||||
win_shell: 'Save-Module -Name PackageManagement, PowerShellGet -Path {{ win_output_dir }} -Force'
|
||||
- name: get result of install package
|
||||
win_shell: Import-Module -Name ansible-test1; Get-AnsibleTest1 | ConvertTo-Json
|
||||
register: install_actual
|
||||
|
||||
- name: unload PackageManagement and PowerShellGet modules
|
||||
win_shell: 'Remove-Module -Name PackageManagement,PowerShellGet -Force -ErrorAction Ignore'
|
||||
ignore_errors: yes
|
||||
- name: assert install package
|
||||
assert:
|
||||
that:
|
||||
- install is changed
|
||||
- install_actual.stdout | from_json == {"Name":"ansible-test1","Version":"1.1.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: get PSModulePath
|
||||
win_shell: "$($Env:PSModulePath -Split ';')[0]"
|
||||
register: psmodulepath
|
||||
- name: install package (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: present
|
||||
register: install_again
|
||||
|
||||
- name: remove older versions of the PackageManagement and PowerShellGet
|
||||
win_file:
|
||||
path: "{{ psmodulepath.stdout | trim }}\\{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- PackageManagement
|
||||
- PowerShellGet
|
||||
- name: assert install package (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not install_again is changed
|
||||
|
||||
- name: create required folder
|
||||
win_file:
|
||||
path: "{{ psmodulepath.stdout | trim }}"
|
||||
state: directory
|
||||
- name: remove package (check mode)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: absent
|
||||
register: remove_check
|
||||
check_mode: yes
|
||||
|
||||
- name: update PowerShellGet and PackageManagement modules
|
||||
win_shell: 'Copy-Item -Path {{ win_output_dir }}\{{ item }} -Destination {{ psmodulepath.stdout | trim }}\ -Recurse -Force'
|
||||
with_items:
|
||||
- PackageManagement
|
||||
- PowerShellGet
|
||||
- name: get result of remove package (check mode)
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test1 | Measure-Object).Count
|
||||
register: remove_actual_check
|
||||
|
||||
- name: update NuGet version
|
||||
when: powershell_major_version.stdout | int >= 5
|
||||
win_shell: |
|
||||
$nuget_exists = (Get-PackageProvider | Where-Object { $_.Name -eq 'Nuget' } | Measure-Object).Count -eq 1
|
||||
- name: remove package (check mode)
|
||||
assert:
|
||||
that:
|
||||
- remove_check is changed
|
||||
- remove_actual_check.stdout | trim | int == 1
|
||||
|
||||
if ( $nuget_exists ) {
|
||||
$nuget_outdated = (Get-PackageProvider -Name NuGet -ErrorAction Ignore).Version -lt [Version]"2.8.5.201"
|
||||
}
|
||||
- name: remove package
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: absent
|
||||
register: remove
|
||||
|
||||
if ( -not $nuget_exists -or $nuget_outdated ) {
|
||||
Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force
|
||||
}
|
||||
- name: get result of remove package
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test1 | Measure-Object).Count
|
||||
register: remove_actual
|
||||
|
||||
- name: perform cleanup before tests run
|
||||
include: clean.yml
|
||||
- name: assert remove package
|
||||
assert:
|
||||
that:
|
||||
- remove is changed
|
||||
- remove_actual.stdout | trim | int == 0
|
||||
|
||||
- name: run tests
|
||||
include: tests.yml
|
||||
- name: remove package (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: absent
|
||||
register: remove_again
|
||||
|
||||
- name: peform legacy (backward compatibility) tests
|
||||
when: powershell_major_version.stdout | int == 5
|
||||
block:
|
||||
- name: perform cleanup before legacy tests run
|
||||
include: clean.yml
|
||||
- name: assert remove package (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not remove_again is changed
|
||||
|
||||
- name: run legacy tests
|
||||
include: tests_legacy.yml
|
||||
- name: fail to install module that exists in multiple repos
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
state: present
|
||||
register: fail_multiple_pkg
|
||||
failed_when: 'fail_multiple_pkg.msg != "Problems installing ansible-test2 module: Unable to install, multiple modules matched ''ansible-test2''. Please specify a single -Repository."'
|
||||
|
||||
- name: install module with specific repository
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
repository: PSRepo 2
|
||||
state: present
|
||||
register: install_repo
|
||||
|
||||
- name: get result of install module with specific repository
|
||||
win_shell: Import-Module -Name ansible-test2; Get-AnsibleTest2 | ConvertTo-Json
|
||||
register: install_repo_actual
|
||||
|
||||
- name: assert install module with specific repository
|
||||
assert:
|
||||
that:
|
||||
- install_repo is changed
|
||||
- install_repo_actual.stdout | from_json == {"Name":"ansible-test2","Version":"1.0.0","Repo":"PSRepo 2"}
|
||||
|
||||
- name: install module with specific repository (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
repository: PSRepo 2
|
||||
state: present
|
||||
register: install_repo_again
|
||||
|
||||
- name: assert install module with specific repository (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not install_repo_again is changed
|
||||
|
||||
- name: remove package that was installed from specific repository
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
state: absent
|
||||
register: remove_repo_without_source
|
||||
|
||||
- name: get result of remove package that was installed from specific repository
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test2 | Measure-Object).Count
|
||||
register: remove_repo_without_source_actual
|
||||
|
||||
- name: assert remove package that was installed from specific repository
|
||||
assert:
|
||||
that:
|
||||
- remove_repo_without_source is changed
|
||||
- remove_repo_without_source_actual.stdout | trim | int == 0
|
||||
|
||||
- name: fail to install required version that is missing
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
required_version: 0.9.0
|
||||
state: present
|
||||
register: fail_missing_req
|
||||
failed_when: '"Problems installing ansible-test1 module: No match was found for the specified search criteria" not in fail_missing_req.msg'
|
||||
|
||||
- name: install required version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
required_version: 1.0.0
|
||||
state: present
|
||||
register: install_req_version
|
||||
|
||||
- name: get result of install required version
|
||||
win_shell: Import-Module -Name ansible-test1; Get-AnsibleTest1 | ConvertTo-Json
|
||||
register: install_req_version_actual
|
||||
|
||||
- name: assert install required version
|
||||
assert:
|
||||
that:
|
||||
- install_req_version is changed
|
||||
- install_req_version_actual.stdout | from_json == {"Name":"ansible-test1","Version":"1.0.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: install required version (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
required_version: 1.0.0
|
||||
state: present
|
||||
register: install_req_version_again
|
||||
|
||||
- name: assert install required version (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not install_req_version_again is changed
|
||||
|
||||
- name: remove required version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
required_version: 1.0.0
|
||||
state: absent
|
||||
register: remove_req_version
|
||||
|
||||
- name: get result of remove required version
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test1 | Measure-Object).Count
|
||||
register: remove_req_version_actual
|
||||
|
||||
- name: assert remove required version
|
||||
assert:
|
||||
that:
|
||||
- remove_req_version is changed
|
||||
- remove_req_version_actual.stdout | trim | int == 0
|
||||
|
||||
- name: remove required version (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
required_version: 1.0.0
|
||||
state: absent
|
||||
register: remove_req_version_again
|
||||
|
||||
- name: assert remove required version (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not remove_req_version_again is changed
|
||||
|
||||
- name: install min max version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
minimum_version: 1.0.1
|
||||
maximum_version: 1.0.9
|
||||
state: present
|
||||
register: install_min_max
|
||||
|
||||
- name: get result of install min max version
|
||||
win_shell: Import-Module -Name ansible-test1; Get-AnsibleTest1 | ConvertTo-Json
|
||||
register: install_min_max_actual
|
||||
|
||||
- name: assert install min max version
|
||||
assert:
|
||||
that:
|
||||
- install_min_max is changed
|
||||
- install_min_max_actual.stdout | from_json == {"Name":"ansible-test1","Version":"1.0.5","Repo":"PSRepo 1"}
|
||||
|
||||
- name: install min max version (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
minimum_version: 1.0.1
|
||||
maximum_version: 1.0.9
|
||||
state: present
|
||||
register: install_min_max_again
|
||||
|
||||
- name: assert install min max version (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not install_min_max_again is changed
|
||||
|
||||
- name: update package to latest version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: latest
|
||||
register: update_module
|
||||
|
||||
- name: get result of update package to latest version
|
||||
win_shell: Import-Module -Name ansible-test1; Get-AnsibleTest1 | ConvertTo-Json
|
||||
register: update_module_actual
|
||||
|
||||
- name: assert update package to latest version
|
||||
assert:
|
||||
that:
|
||||
- update_module is changed
|
||||
- update_module_actual.stdout | from_json == {"Name":"ansible-test1","Version":"1.1.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: update package to latest version (idempotent)
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: latest
|
||||
register: update_module_again
|
||||
|
||||
- name: assert update package to latest version (idempotent)
|
||||
assert:
|
||||
that:
|
||||
- not update_module_again is changed
|
||||
|
||||
- name: remove package that does not match min version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
minimum_version: 2.0.0
|
||||
state: absent
|
||||
register: remove_min_no_change
|
||||
|
||||
- name: assert remove package that does not match min version
|
||||
assert:
|
||||
that:
|
||||
- not remove_min_no_change is changed
|
||||
|
||||
- name: remove package that does not match max version
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
maximum_version: 0.9.0
|
||||
state: absent
|
||||
register: remove_max_no_change
|
||||
|
||||
- name: assert remove package that does not match max version
|
||||
assert:
|
||||
that:
|
||||
- not remove_max_no_change is changed
|
||||
|
||||
- name: uninstall package to clear tests
|
||||
win_psmodule:
|
||||
name: ansible-test1
|
||||
state: absent
|
||||
|
||||
- name: install package with max version
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
maximum_version: 1.0.0
|
||||
repository: PSRepo 1
|
||||
state: present
|
||||
register: install_max
|
||||
|
||||
- name: get result of install package with max version
|
||||
win_shell: Import-Module -Name ansible-test2; Get-AnsibleTest2 | ConvertTo-Json
|
||||
register: install_max_actual
|
||||
|
||||
- name: assert install package with max version
|
||||
assert:
|
||||
that:
|
||||
- install_max is changed
|
||||
- install_max_actual.stdout | from_json == {"Name":"ansible-test2","Version":"1.0.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: fail to install updated package without skip publisher
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
required_version: 1.0.1 # This version has been pureposefully not been signed for testing
|
||||
repository: PSRepo 1
|
||||
state: present
|
||||
register: fail_skip_pub
|
||||
failed_when: '"The version ''1.0.1'' of the module ''ansible-test2'' being installed is not catalog signed" not in fail_skip_pub.msg'
|
||||
|
||||
- name: install updated package provider with skip publisher
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
required_version: 1.0.1
|
||||
repository: PSRepo 1
|
||||
state: present
|
||||
skip_publisher_check: yes
|
||||
register: install_skip_pub
|
||||
|
||||
- name: get result of install updated package provider with skip publisher
|
||||
win_shell: Import-Module -Name ansible-test2; Get-AnsibleTest2 | ConvertTo-Json
|
||||
register: install_skip_pub_actual
|
||||
|
||||
- name: assert install updated package provider with skip publisher
|
||||
assert:
|
||||
that:
|
||||
- install_skip_pub is changed
|
||||
- install_skip_pub_actual.stdout | from_json == {"Name":"ansible-test2","Version":"1.0.1","Repo":"PSRepo 1"}
|
||||
|
||||
- name: remove test package 2 for clean test
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
state: absent
|
||||
|
||||
- name: fail to install clobbered module
|
||||
win_psmodule:
|
||||
name: ansible-clobber
|
||||
state: present
|
||||
register: fail_clobbering_time
|
||||
failed_when: '"If you still want to install this module ''ansible-clobber'', use -AllowClobber parameter." not in fail_clobbering_time.msg'
|
||||
|
||||
- name: install clobbered module
|
||||
win_psmodule:
|
||||
name: ansible-clobber
|
||||
allow_clobber: yes
|
||||
state: present
|
||||
register: install_clobber
|
||||
|
||||
- name: get result of install clobbered module
|
||||
win_shell: Import-Module -Name ansible-clobber; Enable-PSTrace | ConvertTo-Json
|
||||
register: install_clobber_actual
|
||||
|
||||
- name: assert install clobbered module
|
||||
assert:
|
||||
that:
|
||||
- install_clobber is changed
|
||||
- install_clobber_actual.stdout | from_json == {"Name":"ansible-clobber","Version":"0.1.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: remove clobbered module
|
||||
win_psmodule:
|
||||
name: ansible-clobber
|
||||
state: absent
|
||||
register: remove_clobber
|
||||
|
||||
- name: get result of remove clobbered module
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-clobber | Measure-Object).Count
|
||||
register: remove_clobber_actual
|
||||
|
||||
- name: assert remove clobbered module
|
||||
assert:
|
||||
that:
|
||||
- remove_clobber is changed
|
||||
- remove_clobber_actual.stdout | trim | int == 0
|
||||
|
||||
- name: fail to install prerelese module
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
repository: PSRepo 1
|
||||
required_version: 1.1.0-beta1
|
||||
state: present
|
||||
register: fail_install_prerelease
|
||||
failed_when: '"The ''-AllowPrerelease'' parameter must be specified when using the Prerelease string" not in fail_install_prerelease.msg'
|
||||
|
||||
- name: install prerelease module
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
repository: PSRepo 1
|
||||
required_version: 1.1.0-beta1
|
||||
allow_prerelease: yes
|
||||
state: present
|
||||
register: install_prerelease
|
||||
|
||||
- name: get result of install prerelease module
|
||||
win_shell: Import-Module -Name ansible-test2; Get-AnsibleTest2 | ConvertTo-Json
|
||||
register: install_prerelease_actual
|
||||
|
||||
- name: assert install prerelease module
|
||||
assert:
|
||||
that:
|
||||
- install_prerelease is changed
|
||||
- install_prerelease_actual.stdout | from_json == {"Name":"ansible-test2","Version":"1.1.0","Repo":"PSRepo 1"}
|
||||
|
||||
- name: remove prerelease module
|
||||
win_psmodule:
|
||||
name: ansible-test2
|
||||
state: absent
|
||||
register: remove_prerelease
|
||||
|
||||
- name: get result of remove prerelease module
|
||||
win_shell: (Get-Module -ListAvailable -Name ansible-test2 | Measure-Object).Count
|
||||
register: remove_prerelease_actual
|
||||
|
||||
- name: assert remove prerelease module
|
||||
assert:
|
||||
that:
|
||||
- remove_prerelease is changed
|
||||
- remove_prerelease_actual.stdout | trim | int == 0
|
||||
|
|
115
test/integration/targets/win_psmodule/tasks/setup.yml
Normal file
115
test/integration/targets/win_psmodule/tasks/setup.yml
Normal file
|
@ -0,0 +1,115 @@
|
|||
# Sets up 2 local repos that contains mock packages for testing.
|
||||
#
|
||||
# PSRepo 1 contains
|
||||
# ansible-test1 - 1.0.0
|
||||
# ansible-test1 - 1.0.5
|
||||
# ansible-test1 - 1.1.0
|
||||
# ansible-test2 - 1.0.0
|
||||
# ansible-test2 - 1.0.1 (Not signed for skip_publisher tests)
|
||||
# ansible-test2 - 1.1.0-beta1
|
||||
# ansible-clobber - 0.1.0
|
||||
#
|
||||
# PSRepo 2 contains
|
||||
# ansible-test2 - 1.0.0
|
||||
#
|
||||
# These modules will have the following cmdlets
|
||||
# ansible-test1
|
||||
# Get-AnsibleTest1
|
||||
#
|
||||
# ansible-test2
|
||||
# Get-AnsibleTest2
|
||||
#
|
||||
# ansible-clobber
|
||||
# Enable-PSTrace (clobbers the Enable-PSTrace cmdlet)
|
||||
#
|
||||
# All cmdlets return
|
||||
# [PSCustomObject]@{
|
||||
# Name = "the name of the module"
|
||||
# Version = "the version of the module"
|
||||
# Repo = "the repo where the module was sourced from"
|
||||
# }
|
||||
---
|
||||
- name: create test repo folders
|
||||
win_file:
|
||||
path: '{{ remote_tmp_dir }}\{{ item }}'
|
||||
state: directory
|
||||
loop:
|
||||
- PSRepo 1
|
||||
- PSRepo 2
|
||||
|
||||
- name: register test repos
|
||||
win_psrepository:
|
||||
name: '{{ item.name }}'
|
||||
source: '{{ remote_tmp_dir }}\{{ item.name }}'
|
||||
installation_policy: '{{ item.policy }}'
|
||||
notify: remove registered repos
|
||||
loop:
|
||||
- name: PSRepo 1
|
||||
policy: trusted
|
||||
- name: PSRepo 2
|
||||
policy: untrusted
|
||||
|
||||
- name: remove PSGallery repository
|
||||
win_psrepository:
|
||||
name: PSGallery
|
||||
state: absent
|
||||
notify: re-add PSGallery repository
|
||||
|
||||
- name: create custom openssl conf
|
||||
copy:
|
||||
src: openssl.conf
|
||||
dest: '{{ output_dir }}/openssl.conf'
|
||||
delegate_to: localhost
|
||||
|
||||
- name: get absolute path of output_dir for script
|
||||
shell: echo {{ output_dir }}
|
||||
delegate_to: localhost
|
||||
register: output_dir_abs
|
||||
|
||||
- name: create certificates for code signing
|
||||
script: setup_certs.sh
|
||||
args:
|
||||
chdir: '{{ output_dir_abs.stdout }}'
|
||||
delegate_to: localhost
|
||||
|
||||
- name: copy the CA and sign certificates
|
||||
win_copy:
|
||||
src: '{{ output_dir }}/{{ item }}'
|
||||
dest: '{{ remote_tmp_dir }}\'
|
||||
loop:
|
||||
- ca.pem
|
||||
- sign.pem
|
||||
- sign.pfx
|
||||
|
||||
- name: import the CA key to the trusted root store
|
||||
win_certificate_store:
|
||||
path: '{{ remote_tmp_dir }}\ca.pem'
|
||||
state: present
|
||||
store_location: LocalMachine
|
||||
store_name: Root
|
||||
register: ca_cert_import
|
||||
notify: remove CA cert from trusted root store
|
||||
|
||||
- name: import the sign key to the trusted publisher store
|
||||
win_certificate_store:
|
||||
path: '{{ remote_tmp_dir }}\sign.pem'
|
||||
state: present
|
||||
store_location: LocalMachine
|
||||
store_name: TrustedPublisher
|
||||
register: sign_cert_import
|
||||
notify: remove signing key from trusted publisher store
|
||||
|
||||
- name: copy across module template files
|
||||
win_copy:
|
||||
src: module/
|
||||
dest: '{{ remote_tmp_dir }}'
|
||||
|
||||
# Used in the script below to create the .nupkg for each test module
|
||||
- name: download NuGet binary for module publishing
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/nuget.exe
|
||||
dest: '{{ remote_tmp_dir }}'
|
||||
|
||||
- name: create test PowerShell modules
|
||||
script: setup_modules.ps1 "{{ remote_tmp_dir }}"
|
||||
notify: remove test packages
|
|
@ -1,808 +0,0 @@
|
|||
# This file is part of Ansible
|
||||
|
||||
# test code for the win_psmodule module when using winrm connection
|
||||
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net>
|
||||
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
---
|
||||
|
||||
- name: "get the latest version of the {{ powershell_module }} module in PowerShell Gallery"
|
||||
win_shell: "((Find-Module -Name {{ powershell_module }}).Version).ToString()"
|
||||
changed_when: false
|
||||
register: module_latest_version
|
||||
|
||||
- name: "get {{ skip_publisher_check_module }} is preinstalled"
|
||||
win_shell: "(Get-Module -Name {{ skip_publisher_check_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count"
|
||||
register: skip_publisher_module_exist
|
||||
|
||||
- name: "check installing module from Powershell Gallery - without version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
check_mode: yes
|
||||
register: module_without_version_setup_1
|
||||
|
||||
- name: get result installing module from Powershell Gallery - without version
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ module_latest_version.stdout | trim }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_without_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - without version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_without_version_setup_1 is changed
|
||||
- result_module_without_version_setup_1.stdout | trim | bool == false
|
||||
|
||||
- name: "check installing module from Powershell Gallery - without version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
register: module_without_version_setup_1
|
||||
|
||||
- name: "get result installing module from Powershell Gallery - without version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ module_latest_version.stdout | trim }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_without_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - without version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_without_version_setup_1 is changed
|
||||
- result_module_without_version_setup_1.stdout | trim | bool == true
|
||||
|
||||
- name: check idempotency installing module from PowerShell Gallery - without version
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
register: module_without_version_setup_2
|
||||
|
||||
- name: test idempotency installing module from PowerShell Gallery - without version
|
||||
assert:
|
||||
that:
|
||||
- module_without_version_setup_2 is not changed
|
||||
|
||||
- name: "check uninstalling PowerShell module - without version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_without_version
|
||||
|
||||
- name: "get result uninstalling PowerShell module - without version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable | Measure-Object ).Count -ge 1"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_without_version
|
||||
|
||||
- name: "test uninstalling PowerShell module - without version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_without_version is changed
|
||||
- result_module_uninstall_without_version.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstalling PowerShell module - without version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_without_version
|
||||
|
||||
- name: "get result uninstalling PowerShell module - without version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable | Measure-Object ).Count -eq 0"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_without_version
|
||||
|
||||
- name: "test uninstalling PowerShell module - without version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_without_version is changed
|
||||
- result_module_uninstall_without_version.stdout | trim | bool == true
|
||||
|
||||
- name: check idempotency uninstalling PowerShell module - without version
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_2
|
||||
|
||||
- name: test idempotency uninstalling PowerShell module - without version
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_2 is not changed
|
||||
|
||||
- name: "check installing module from Powershell Gallery - required_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: present
|
||||
check_mode: yes
|
||||
register: module_required_version_setup_1
|
||||
|
||||
- name: "get result installing module from Powershell Gallery - required_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_required_version }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_required_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - required_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_required_version_setup_1 is changed
|
||||
- result_module_required_version_setup_1.stdout | trim | bool == false
|
||||
|
||||
- name: "check installing module from Powershell Gallery - required_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: present
|
||||
register: module_required_version_setup_1
|
||||
|
||||
- name: "get result installing module from Powershell Gallery - required_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_required_version }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_required_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - required_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_required_version_setup_1 is changed
|
||||
- result_module_required_version_setup_1.stdout | trim | bool == true
|
||||
|
||||
- name: check idempotency installing module from Powershell Gallery - required_version
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: present
|
||||
register: module_required_version_setup_2
|
||||
|
||||
- name: test idempotency installing module from Powershell Gallery - required_version
|
||||
assert:
|
||||
that:
|
||||
- module_required_version_setup_2 is not changed
|
||||
|
||||
- name: "check uninstall PowerShell module - required_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: absent
|
||||
register: module_uninstall_required_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - required_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_required_version }}' } | Measure-Object).Count -eq 0"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_required_version
|
||||
|
||||
- name: "test PowerShell module uninstall - required_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_required_version is changed
|
||||
- result_module_uninstall_required_version.stdout | trim | bool == true
|
||||
|
||||
- name: check installing module from Powershell Gallery - required_version but not existing
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_ultra_high_version }}"
|
||||
state: present
|
||||
register: module_required_version_setup_3
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test installing module from Powershell Gallery - required_version but not existing
|
||||
assert:
|
||||
that:
|
||||
- module_required_version_setup_3 is not changed
|
||||
- module_required_version_setup_3 is failed
|
||||
- "'Problems installing {{ powershell_module }} module: No match was found for the specified search criteria' in module_required_version_setup_3.msg"
|
||||
|
||||
- name: "check installing module from Powershell Gallery - maximum_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_maximum_version_request }}"
|
||||
state: present
|
||||
check_mode: yes
|
||||
register: module_maximum_version_setup_1
|
||||
|
||||
- name: "get result installing module from Powershell Gallery - maximum_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_maximum_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - maximum_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_maximum_version_setup_1 is changed
|
||||
- result_module_maximum_version_setup_1.stdout | trim | bool == false
|
||||
|
||||
- name: "check installing module from Powershell Gallery - maximum_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_maximum_version_request }}"
|
||||
state: present
|
||||
register: module_maximum_version_setup_1
|
||||
|
||||
- name: "get result installing module from Powershell Gallery - maximum_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_maximum_version_setup_1
|
||||
|
||||
- name: "test installing module from Powershell Gallery - maximum_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_maximum_version_setup_1 is changed
|
||||
- result_module_maximum_version_setup_1.stdout | trim | bool == true
|
||||
|
||||
- name: check idempotency installing module from Powershell Gallery - maximum_version
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_maximum_version_request }}"
|
||||
state: present
|
||||
register: module_maximum_version_setup_2
|
||||
|
||||
- name: test idempotency installing module from Powershell Gallery - maximum_version
|
||||
assert:
|
||||
that:
|
||||
- module_maximum_version_setup_2 is not changed
|
||||
|
||||
- name: "check uninstall PowerShell module - maximum_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_maximum_version_request }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_maximum_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - maximum_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_maximum_version
|
||||
|
||||
- name: "test PowerShell module uninstall - maximum_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_maximum_version is changed
|
||||
- result_module_uninstall_maximum_version.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module - maximum_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_maximum_version_request }}"
|
||||
state: absent
|
||||
register: module_uninstall_maximum_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - maximum_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_maximum_version_result }}' } | Measure-Object).Count -eq 0"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_maximum_version
|
||||
|
||||
- name: "test PowerShell module uninstall - maximum_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_maximum_version is changed
|
||||
- result_module_uninstall_maximum_version.stdout | trim | bool == true
|
||||
|
||||
- name: check installing module from Powershell Gallery - maximum_version but not existing
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
maximum_version: "{{ powershell_module_ultra_low_version }}"
|
||||
state: present
|
||||
register: module_maximum_version_setup_3
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test installing module from Powershell Gallery - maximum_version but not existing
|
||||
assert:
|
||||
that:
|
||||
- module_maximum_version_setup_3 is not changed
|
||||
- module_maximum_version_setup_3 is failed
|
||||
|
||||
# Don't move skip_publisher_check tests below minimum_version and maximum_version tests
|
||||
- name: check installing module with skip_publisher_check not active
|
||||
win_psmodule:
|
||||
name: "{{ skip_publisher_check_module }}"
|
||||
# Adding a required version is required because the tested module
|
||||
# is bundled within OS and has not be digitally signed (since 4.4.3 it's)
|
||||
required_version: "4.2.0"
|
||||
# Run only for systems with built'in module e.g. Windows 10
|
||||
when: skip_publisher_module_exist.stdout | int == 1
|
||||
register: fail_skip_publisher_check
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test installing module with skip_publisher_check not active
|
||||
assert:
|
||||
that:
|
||||
- fail_skip_publisher_check is failed
|
||||
- "'being installed is not catalog signed. Ensure that the version' in fail_skip_publisher_check.msg"
|
||||
when: skip_publisher_module_exist.stdout | int >= 1
|
||||
|
||||
- name: "check installing module with skip_publisher_check active - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ skip_publisher_check_module }}"
|
||||
# Adding a required version is required because the tested module
|
||||
# is bundled within OS and has not be digitally signed (since 4.4.3 it's)
|
||||
required_version: "4.2.0"
|
||||
skip_publisher_check: yes
|
||||
check_mode: yes
|
||||
register: ok_skip_publisher_check
|
||||
|
||||
- name: "get result installing module with skip_publisher_check active - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ skip_publisher_check_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq {{ skip_publisher_module_exist.stdout | int }}"
|
||||
changed_when: false
|
||||
register: result_ok_skip_publisher_check
|
||||
|
||||
- name: "test installing module with skip_publisher_check active - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- ok_skip_publisher_check is changed
|
||||
- result_ok_skip_publisher_check.stdout | trim | bool == true
|
||||
|
||||
- name: "check installing module with skip_publisher_check active - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ skip_publisher_check_module }}"
|
||||
# Adding a required version is required because the tested module
|
||||
# is bundled within OS and has not be digitally signed (since 4.4.3 it's)
|
||||
required_version: "4.2.0"
|
||||
skip_publisher_check: yes
|
||||
register: ok_skip_publisher_check
|
||||
|
||||
- name: "get result installing module with skip_publisher_check active - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ skip_publisher_check_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq {{ skip_publisher_module_exist.stdout | int + 1 }}"
|
||||
changed_when: false
|
||||
register: result_ok_skip_publisher_check
|
||||
|
||||
- name: "test installing module with skip_publisher_check active - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- ok_skip_publisher_check is changed
|
||||
- result_ok_skip_publisher_check.stdout | trim | bool == true
|
||||
|
||||
- name: "check Powershell Gallery module setup - minimum_version and maximum_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module_2 }}"
|
||||
minimum_version: "{{ powershell_module_2_minimum_version_request }}"
|
||||
maximum_version: "{{ powershell_module_2_maximum_version_request }}"
|
||||
skip_publisher_check: yes
|
||||
state: present
|
||||
check_mode: yes
|
||||
register: module_minimum_maximim_version_setup_1
|
||||
|
||||
- name: "get result Powershell Gallery module setup - minimum_version and maximum_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module_2 }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_2_minimum_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_minimum_maximim_version_setup_1
|
||||
|
||||
- name: "test Powershell Gallery module setup - minimum_version and maximum_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_minimum_maximim_version_setup_1 is changed
|
||||
- result_module_minimum_maximim_version_setup_1.stdout | trim | bool == false
|
||||
|
||||
- name: "check Powershell Gallery module setup - minimum_version and maximum_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module_2 }}"
|
||||
minimum_version: "{{ powershell_module_2_minimum_version_request }}"
|
||||
maximum_version: "{{ powershell_module_2_maximum_version_request }}"
|
||||
skip_publisher_check: yes
|
||||
state: present
|
||||
register: module_minimum_maximim_version_setup_1
|
||||
|
||||
- name: "get result Powershell Gallery module setup - minimum_version and maximum_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module_2 }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_2_minimum_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_minimum_maximim_version_setup_1
|
||||
|
||||
- name: "test Powershell Gallery module setup - minimum_version and maximum_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_minimum_maximim_version_setup_1 is changed
|
||||
- result_module_minimum_maximim_version_setup_1.stdout | trim | bool == true
|
||||
|
||||
- name: check idempotency reinstalling module - minimum_version and maximum_version
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module_2 }}"
|
||||
minimum_version: "{{ powershell_module_2_minimum_version_request }}"
|
||||
maximum_version: "{{ powershell_module_2_maximum_version_request }}"
|
||||
state: present
|
||||
register: module_minimum_maximim_version_setup_2
|
||||
|
||||
- name: test idempotency reinstalling module - minimum_version and maximum_version
|
||||
assert:
|
||||
that:
|
||||
- module_minimum_maximim_version_setup_2 is not changed
|
||||
|
||||
- name: "check uninstall PowerShell module - minimum_version and maximum_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module_2 }}"
|
||||
minimum_version: "{{ powershell_module_2_minimum_version_request }}"
|
||||
maximum_version: "{{ powershell_module_2_maximum_version_request }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_minimum_maximum_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - minimum_version and maximum_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module_2 }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_2_minimum_maximum_version_result }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_minimum_maximum_version
|
||||
|
||||
- name: "test uninstall PowerShell module - minimum_version and maximum_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_minimum_maximum_version is changed
|
||||
- result_module_uninstall_minimum_maximum_version.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module - minimum_version and maximum_version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module_2 }}"
|
||||
minimum_version: "{{ powershell_module_2_minimum_version_request }}"
|
||||
maximum_version: "{{ powershell_module_2_maximum_version_request }}"
|
||||
state: absent
|
||||
register: module_uninstall_minimum_maximum_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - minimum_version and maximum_version - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module_2 }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_2_minimum_maximum_version_result }}' } | Measure-Object).Count -eq 0"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_minimum_maximum_version
|
||||
|
||||
- name: "test uninstall PowerShell module - minimum_version and maximum_version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_minimum_maximum_version is changed
|
||||
- result_module_uninstall_minimum_maximum_version.stdout | trim | bool == true
|
||||
|
||||
- name: check installing module with allow_clobber not active
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
register: fail_allow_clobber
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test installing module with allow_clobber not active
|
||||
assert:
|
||||
that:
|
||||
- fail_allow_clobber is failed
|
||||
- "'The following commands are already available on this system' in fail_allow_clobber.msg"
|
||||
|
||||
- name: "check installing module with allow_clobber active - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
allow_clobber: yes
|
||||
check_mode: yes
|
||||
register: ok_allow_clobber
|
||||
|
||||
- name: "get result installing module with allow_clobber active - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ allow_clobber_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_ok_allow_clobber
|
||||
|
||||
- name: "test installing module with allow_clobber active - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- ok_allow_clobber is changed
|
||||
- result_ok_allow_clobber.stdout | trim | bool == false
|
||||
|
||||
- name: "check installing module with allow_clobber active - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
allow_clobber: yes
|
||||
register: ok_allow_clobber
|
||||
|
||||
- name: "get result installing module with allow_clobber active - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ allow_clobber_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_ok_allow_clobber
|
||||
|
||||
- name: "test installing module with allow_clobber active - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- ok_allow_clobber is changed
|
||||
- result_ok_allow_clobber.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module allow_clobber - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_4
|
||||
|
||||
- name: "get uninstall PowerShell module allow_clobber - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ allow_clobber_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq 1"
|
||||
register: result_module_uninstall_4
|
||||
|
||||
- name: "test uninstall PowerShell module allow_clobber - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_4 is changed
|
||||
- result_module_uninstall_4.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module allow_clobber - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_4
|
||||
|
||||
- name: "get uninstall PowerShell module allow_clobber - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ allow_clobber_module }} -ListAvailable -ErrorAction Ignore | Measure-Object).Count -eq 0"
|
||||
register: result_module_uninstall_4
|
||||
|
||||
- name: "test uninstall PowerShell module allow_clobber - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_4 is changed
|
||||
- result_module_uninstall_4.stdout | trim | bool == true
|
||||
|
||||
- name: check installing module with allow_prerelease not active
|
||||
win_psmodule:
|
||||
name: "{{ allow_prerelease_module }}"
|
||||
required_version: "{{ allow_prerelease_version }}"
|
||||
allow_prerelease: no
|
||||
skip_publisher_check: yes
|
||||
register: fail_allow_prerelease
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test installing module with allow_prerelease not active
|
||||
assert:
|
||||
that:
|
||||
- fail_allow_prerelease is failed
|
||||
|
||||
- name: "check installing prerelease module with allow_prerelease active - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ allow_prerelease_module }}"
|
||||
required_version: "{{ allow_prerelease_version }}"
|
||||
allow_prerelease: yes
|
||||
skip_publisher_check: yes
|
||||
check_mode: yes
|
||||
register: ok_allow_prerelease
|
||||
|
||||
- name: "test installing prerelease module with allow_prerelease active - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- ok_allow_prerelease is changed
|
||||
|
||||
- name: "check installing prerelease module with allow_prerelease active - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ allow_prerelease_module }}"
|
||||
required_version: "{{ allow_prerelease_version }}"
|
||||
allow_prerelease: yes
|
||||
skip_publisher_check: yes
|
||||
register: ok_allow_prerelease
|
||||
|
||||
- name: "test installing prerelease module with allow_prerelease active - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- ok_allow_prerelease is changed
|
||||
|
||||
- name: check installing module with a wrong name
|
||||
win_psmodule:
|
||||
name: "{{ wrong_module }}"
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: module_fail
|
||||
|
||||
- name: test installing module with a wrong name
|
||||
assert:
|
||||
that:
|
||||
- module_fail is failed
|
||||
- "'Problems installing {{ wrong_module }} module: No match was found for the specified search criteria' in module_fail.msg"
|
||||
|
||||
- name: check installing module from Powershell Gallery - without version 3
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
register: module_without_version_setup_3
|
||||
|
||||
- name: get result installing module from Powershell Gallery - without version 3
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ module_latest_version.stdout | trim }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_without_version_setup_3
|
||||
|
||||
- name: test Powershell Gallery module setup - without version 3
|
||||
assert:
|
||||
that:
|
||||
- module_without_version_setup_3 is changed
|
||||
- result_module_without_version_setup_3.stdout | trim | bool == true
|
||||
|
||||
- name: check installing module from Powershell Gallery - required_version 4
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: present
|
||||
register: module_required_version_setup_4
|
||||
|
||||
- name: get result installing module from Powershell Gallery - required_version 4
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_required_version }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_required_version_setup_4
|
||||
|
||||
- name: test installing module from Powershell Gallery - required_version 4
|
||||
assert:
|
||||
that:
|
||||
- module_required_version_setup_4 is changed
|
||||
- result_module_required_version_setup_4.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module - required_version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
required_version: "{{ powershell_module_required_version }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_required_version
|
||||
|
||||
- name: "get result uninstall PowerShell module - required_version - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ powershell_module_required_version }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_uninstall_required_version
|
||||
|
||||
- name: "test PowerShell module uninstall - required_version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_required_version is changed
|
||||
- result_module_uninstall_required_version.stdout | trim | bool == true
|
||||
|
||||
- name: "check uninstall PowerShell module - minimum_version - ultra high version - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
minimum_version: "{{ powershell_module_ultra_high_version }}"
|
||||
state: absent
|
||||
check_mode: yes
|
||||
register: module_uninstall_minimum_version
|
||||
|
||||
- name: "test Powershell Gallery module setup - minimum_version - ultra high version - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_minimum_version is not changed
|
||||
|
||||
- name: "check uninstall PowerShell module - minimum_version - ultra high version - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
minimum_version: "{{ powershell_module_ultra_high_version }}"
|
||||
state: absent
|
||||
register: module_uninstall_minimum_version
|
||||
|
||||
- name: "test Powershell Gallery module setup - minimum_version - ultra high version - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_uninstall_minimum_version is not changed
|
||||
|
||||
- name: check fake custom ps repository registration attempt
|
||||
win_psmodule:
|
||||
name: "{{ wrong_module }}"
|
||||
repository: "{{ fake_repo_name }}"
|
||||
ignore_errors: yes
|
||||
register: fake_repo_fail
|
||||
|
||||
- name: test fake custom ps repository registration attempt
|
||||
assert:
|
||||
that:
|
||||
- fake_repo_fail is failed
|
||||
|
||||
- name: check installing module from the My Get repository and registering that repository at the same time
|
||||
win_psmodule:
|
||||
name: "{{ myget_powershell_module }}"
|
||||
repository: "{{ myget_repository_name }}"
|
||||
url: "{{ myget_repository_url }}"
|
||||
state: present
|
||||
register: adding_repository
|
||||
|
||||
- name: get installing module from the My Get repository and registering that repository at the same time
|
||||
win_shell: |
|
||||
$repo = Get-PSRepository -Name {{ myget_repository_name | quote }} -ErrorAction Ignore
|
||||
$module = Get-Module -Name {{ myget_powershell_module }} -ListAvailable
|
||||
($repo | Measure-Object).Count
|
||||
$repo.SourceLocation
|
||||
$repo.InstallationPolicy
|
||||
($module | Measure-Object).Count
|
||||
register: result_adding_repository
|
||||
|
||||
- name: test installing module from the My Get repository and registering that repository at the same time
|
||||
assert:
|
||||
that:
|
||||
- adding_repository is changed
|
||||
- result_adding_repository.stdout_lines[0] == '1'
|
||||
- result_adding_repository.stdout_lines[1] == myget_repository_url
|
||||
- result_adding_repository.stdout_lines[2] == 'Trusted'
|
||||
- result_adding_repository.stdout_lines[3] == '1'
|
||||
|
||||
- name: check uninstalling module from the My Get repository and unregistering that repository at the same time
|
||||
win_psmodule:
|
||||
name: "{{ myget_powershell_module }}"
|
||||
repository: "{{ myget_repository_name }}"
|
||||
state: absent
|
||||
register: removing_repository
|
||||
|
||||
- name: get uninstalling module from the My Get repository and registering that repository at the same time
|
||||
win_shell: |
|
||||
$repo = Get-PSRepository -Name {{ myget_repository_name | quote }} -ErrorAction Ignore
|
||||
$module = Get-Module -Name {{ myget_powershell_module }} -ListAvailable
|
||||
($repo | Measure-Object).Count
|
||||
($module | Measure-Object).Count
|
||||
register: result_removing_repository
|
||||
|
||||
- name: test uninstalling module from the My Get repository and registering that repository at the same time
|
||||
assert:
|
||||
that:
|
||||
- removing_repository is changed
|
||||
- result_removing_repository.stdout_lines[0] == '0'
|
||||
- result_removing_repository.stdout_lines[1] == '0'
|
||||
|
||||
# I don't know why Publish-Module doesn't work correctly under Ansible and PowerShell 3.0
|
||||
- name: check operations related to the custom repository
|
||||
when: powershell_major_version.stdout | int >= 4
|
||||
block:
|
||||
- name: "check sample module is uninstalled - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_4
|
||||
|
||||
- name: "create repository path - check mode: false"
|
||||
win_file:
|
||||
path: "{{custom_repo_path}}"
|
||||
state: directory
|
||||
|
||||
- name: "copy some module to custom repo - check mode: false"
|
||||
win_shell: |
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
Save-Module -Name "{{powershell_module}}" -Repository PSGallery -Path $env:Temp | Out-Null
|
||||
|
||||
$repoName = "{{custom_repo_name}}"
|
||||
$repoPath = "{{custom_repo_path}}"
|
||||
|
||||
Register-PSRepository -Name $repoName -SourceLocation $repoPath -InstallationPolicy Trusted | Out-Null
|
||||
|
||||
Publish-Module -Repository PSRegisterRepo -Path "$env:temp\Powershell-yaml" -Force -Confirm:$false -Verbose | Out-Null
|
||||
|
||||
Start-Sleep -Seconds 15
|
||||
|
||||
Get-ChildItem -Path $repoPath\* -include *.nupkg | Where-Object { $_.Name -match "{{powershell_module}}" } | ForEach-Object { $_.Name }
|
||||
|
||||
register: saved_package
|
||||
|
||||
- name: "check installing module from custom Powershell repository - check mode: true"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
repository: "{{custom_repo_name}}"
|
||||
check_mode: yes
|
||||
register: module_from_custom_repo
|
||||
|
||||
- name: "test sample module in custom repo - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- powershell_module | lower in ((saved_package.stdout_lines | last) | lower)
|
||||
|
||||
- name: "get the latest version of module in custom repo"
|
||||
win_shell: "((Find-Module -Name {{ powershell_module }} -Repository {{custom_repo_name}}).Version).ToString()"
|
||||
changed_when: false
|
||||
register: saved_module_latest_version
|
||||
|
||||
- name: "get result installing module from custom Powershell repository - check mode: true"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ saved_module_latest_version.stdout }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_from_custom_repo
|
||||
|
||||
- name: "test installing module from custom Powershell repository - check mode: true"
|
||||
assert:
|
||||
that:
|
||||
- module_from_custom_repo is changed
|
||||
- result_module_from_custom_repo.stdout | trim | bool == false
|
||||
|
||||
- name: "check installing module from custom Powershell repository - check mode: false"
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
repository: "{{custom_repo_name}}"
|
||||
register: module_from_custom_repo
|
||||
|
||||
- name: "get result installing module from custom Powershell repository - check mode: false"
|
||||
win_shell: "(Get-Module -Name {{ powershell_module }} -ListAvailable -ErrorAction Ignore | Where-Object { $_.Version -eq '{{ saved_module_latest_version.stdout }}' } | Measure-Object).Count -eq 1"
|
||||
changed_when: false
|
||||
register: result_module_from_custom_repo
|
||||
|
||||
- name: "test installing module from custom Powershell repository - check mode: false"
|
||||
assert:
|
||||
that:
|
||||
- module_from_custom_repo is changed
|
||||
- result_module_from_custom_repo.stdout | trim | bool == true
|
||||
|
||||
- name: test module was installed from custom repo
|
||||
win_shell: "(Get-InstalledModule -Name {{ powershell_module }}).Repository"
|
||||
register: is_package_customrepo
|
||||
|
||||
- name: test sample module is installed from custom repo
|
||||
assert:
|
||||
that:
|
||||
- is_package_customrepo.stdout_lines[0] == custom_repo_name
|
|
@ -1,216 +0,0 @@
|
|||
# This file is part of Ansible
|
||||
|
||||
# test code for the win_psmodule module when using winrm connection
|
||||
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
---
|
||||
|
||||
# The file contains tests for backward compatibility only - for Ansible < 2.8.
|
||||
# They should be removed under a deprecation of the functionalities for adding/removing
|
||||
# repositories.
|
||||
|
||||
- name: install module from Powershell Gallery
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
register: module_setup
|
||||
|
||||
- name: test Powershell Gallery module setup
|
||||
assert:
|
||||
that:
|
||||
- "module_setup is changed"
|
||||
- "module_setup.output == 'Module {{ powershell_module }} installed'"
|
||||
|
||||
- name: check idempotency reinstalling module
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
register: module_reinstall
|
||||
|
||||
- name: test win_psmodule idempotency
|
||||
assert:
|
||||
that:
|
||||
- "module_reinstall is not changed"
|
||||
|
||||
- name: check module install with allow_clobber not active
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
register: fail_allow_clobber
|
||||
ignore_errors: yes
|
||||
|
||||
- name: test allow_clobber has failed
|
||||
assert:
|
||||
that:
|
||||
- "fail_allow_clobber is failed"
|
||||
|
||||
- name: check module install with allow_clobber active
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
allow_clobber: yes
|
||||
register: ok_allow_clobber
|
||||
|
||||
- name: test module install with allow_clobber active
|
||||
assert:
|
||||
that:
|
||||
- "ok_allow_clobber is changed"
|
||||
|
||||
- name: check wrong module install attempt
|
||||
win_psmodule:
|
||||
name: "{{ wrong_module }}"
|
||||
state: present
|
||||
ignore_errors: yes
|
||||
register: module_fail
|
||||
|
||||
- name: test module setup fails
|
||||
assert:
|
||||
that:
|
||||
- "module_fail is failed"
|
||||
|
||||
- name: check fake custom ps repository registration attempt
|
||||
win_psmodule:
|
||||
name: "{{ wrong_module }}"
|
||||
repository: Fake repository
|
||||
url: http://my_fake_repo.com/repo/
|
||||
ignore_errors: yes
|
||||
register: repo_fail
|
||||
|
||||
- name: test fake custom ps repository registration attempt
|
||||
assert:
|
||||
that:
|
||||
- "repo_fail is failed"
|
||||
|
||||
- name: check module is installed
|
||||
win_shell: (Get-Module -Name {{ powershell_module }} -ListAvailable).Name
|
||||
register: module_check
|
||||
|
||||
- name: test module is installed
|
||||
assert:
|
||||
that:
|
||||
- "module_check.stdout_lines[0] == '{{ powershell_module }}'"
|
||||
|
||||
- name: check allow_clobber module is installed
|
||||
win_shell: (Get-Module -Name {{ allow_clobber_module }} -ListAvailable).Name
|
||||
register: allow_clobber_check
|
||||
|
||||
- name: test allow_clobber module is installed
|
||||
assert:
|
||||
that:
|
||||
- "allow_clobber_check.stdout_lines[0] == '{{ allow_clobber_module }}'"
|
||||
|
||||
- name: remove installed powershell module
|
||||
win_psmodule:
|
||||
name: powershell-yaml
|
||||
state: absent
|
||||
register: module_uninstall
|
||||
|
||||
- name: test powershell module removal
|
||||
assert:
|
||||
that:
|
||||
- "module_uninstall is changed"
|
||||
- "module_uninstall.output == 'Module {{ powershell_module }} removed'"
|
||||
|
||||
- name: check module is uninstalled
|
||||
win_shell: (Get-Module -Name {{ powershell_module }} -ListAvailable).Name
|
||||
register: module_check
|
||||
|
||||
- name: test module is no more present
|
||||
assert:
|
||||
that:
|
||||
- "module_check.stdout == ''"
|
||||
|
||||
- name: check idempotency re-removing module
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_2
|
||||
|
||||
- name: test idempotency
|
||||
assert:
|
||||
that:
|
||||
- "module_uninstall_2 is not changed"
|
||||
|
||||
- name: check removing allow_clobber module
|
||||
win_psmodule:
|
||||
name: "{{ allow_clobber_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_3
|
||||
|
||||
- name: test removing allow_clobber module
|
||||
assert:
|
||||
that:
|
||||
- "module_uninstall_2 is not changed"
|
||||
- "module_uninstall_3 is changed"
|
||||
|
||||
- name: Create repository path
|
||||
win_file:
|
||||
path: "{{custom_repo_path}}"
|
||||
state: directory
|
||||
|
||||
- name: Make sure sample module is uninstalled
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: absent
|
||||
register: module_uninstall_4
|
||||
|
||||
- name: Copy some module to custom repo
|
||||
win_shell: |
|
||||
# Need PSGet 1.6.0 for publishing and named repo usage
|
||||
$psg = [PSCustomObject]@{ n="PowerShellGet"; v="1.6.0"}
|
||||
Remove-Module -Name $psg.n -Force -ErrorAction SilentlyContinue
|
||||
Import-PackageProvider -Name $psg.n -RequiredVersion $psg.v -ErrorVariable missingProvider -Force | Out-Null
|
||||
|
||||
if($missingProvider){
|
||||
Install-PackageProvider -Name $psg.n -RequiredVersion $psg.v -Confirm:$false -Force | Out-Null
|
||||
|
||||
# Unload previous version
|
||||
Remove-Module -Name $psg.n -Force -ErrorAction SilentlyContinue;
|
||||
Import-PackageProvider -Name $psg.n -RequiredVersion $psg.v -Force | Out-Null
|
||||
}
|
||||
|
||||
$modName = "{{powershell_module}}"
|
||||
$temp = $env:Temp
|
||||
|
||||
Save-Module -Name $modName -Repository PSGallery -Path $temp | Out-Null
|
||||
|
||||
$repoName = "{{custom_repo_name}}"
|
||||
$repoPath = "{{custom_repo_path}}"
|
||||
|
||||
if(!(Test-Path $repoPath)){
|
||||
New-Item -Type Directory $repoPath -Force | Out-Null
|
||||
}
|
||||
|
||||
Register-PSRepository -Name $repoName -SourceLocation $repoPath -InstallationPolicy Trusted | Out-Null
|
||||
|
||||
Publish-Module -Path "$temp\\$modName" -Repository $repoName -Force -Confirm:$false | Out-Null
|
||||
Get-ChildItem -Path "$repoPath\\*" | Where-Object { $_.Name -match "$modName.*.nupkg" } | ForEach-Object { $_.Name }
|
||||
|
||||
register: saved_package
|
||||
|
||||
- name: Validate sample module in custom repo
|
||||
assert:
|
||||
that:
|
||||
- "powershell_module in (saved_package.stdout_lines | last)"
|
||||
|
||||
- name: Install module from custom Powershell repository
|
||||
win_psmodule:
|
||||
name: "{{ powershell_module }}"
|
||||
state: present
|
||||
repository: "{{custom_repo_name}}"
|
||||
url: "{{custom_repo_path}}"
|
||||
register: module_from_custom_repo
|
||||
|
||||
- name: Test custom Powershell repository module install
|
||||
assert:
|
||||
that:
|
||||
- "module_from_custom_repo is changed"
|
||||
- "module_from_custom_repo.output == 'Module {{ powershell_module }} installed'"
|
||||
|
||||
- name: Verify module was installed from custom repo
|
||||
win_shell: (Get-InstalledModule -Name "{{powershell_module}}").Repository
|
||||
register: is_package_customrepo
|
||||
|
||||
- name: Validate sample module is installed from custom repo
|
||||
assert:
|
||||
that:
|
||||
- "is_package_customrepo.stdout_lines[0] == custom_repo_name"
|
|
@ -1,4 +1,4 @@
|
|||
---
|
||||
repository_name: My Get
|
||||
repository_sourcelocation: https://www.myget.org/F/powershellgetdemo/api/v2
|
||||
repository_sourcelocation2: '{{ win_output_dir }}'
|
||||
repository_sourcelocation2: '{{ remote_tmp_dir }}'
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
dependencies:
|
||||
- prepare_win_tests
|
||||
- setup_remote_tmp_dir
|
||||
- setup_win_psget
|
||||
|
|
|
@ -4,83 +4,13 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
---
|
||||
|
||||
- name: get PowerShell version
|
||||
win_shell: '$PSVersionTable.PSVersion.Major'
|
||||
register: powershell_major_version
|
||||
|
||||
- name: update PackageManagement and PowerShellGet when PowerShell < 5.0
|
||||
when: powershell_major_version.stdout | int < 5
|
||||
block:
|
||||
- name: download PackageManagement
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/PackageManagement_x64.msi
|
||||
dest: '{{ win_output_dir }}\PackageManagement_x64.msi'
|
||||
|
||||
- name: install PackageManagement
|
||||
win_package:
|
||||
path: '{{ win_output_dir }}\PackageManagement_x64.msi'
|
||||
state: present
|
||||
|
||||
- name: create the required folder
|
||||
win_file:
|
||||
path: 'C:\Program Files\PackageManagement\ProviderAssemblies'
|
||||
state: directory
|
||||
|
||||
- name: download nuget
|
||||
win_get_url:
|
||||
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/win_psmodule/nuget.exe
|
||||
dest: 'C:\Program Files\PackageManagement\ProviderAssemblies\NuGet-anycpu.exe'
|
||||
|
||||
- name: update NuGet provider
|
||||
win_shell: 'Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies'
|
||||
|
||||
- name: download and save the nevest version of the PackageManagement module from PowerShell Gallery
|
||||
win_shell: 'Save-Module -Name PackageManagement, PowerShellGet -Path {{ win_output_dir }} -Force'
|
||||
|
||||
- name: unload PackageManagement and PowerShellGet modules
|
||||
win_shell: 'Remove-Module -Name PackageManagement,PowerShellGet -Force -ErrorAction Ignore'
|
||||
ignore_errors: yes
|
||||
|
||||
- name: get PSModulePath
|
||||
win_shell: "$($Env:PSModulePath -Split ';')[0]"
|
||||
register: psmodulepath
|
||||
|
||||
- name: remove older versions of the PackageManagement and PowerShellGet
|
||||
win_file:
|
||||
path: "{{ psmodulepath.stdout | trim }}\\{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- PackageManagement
|
||||
- PowerShellGet
|
||||
|
||||
- name: create required folder
|
||||
win_file:
|
||||
path: "{{ psmodulepath.stdout | trim }}"
|
||||
state: directory
|
||||
|
||||
- name: update PowerShellGet and PackageManagement modules
|
||||
win_shell: 'Copy-Item -Path {{ win_output_dir }}\{{ item }} -Destination {{ psmodulepath.stdout | trim }}\ -Recurse -Force'
|
||||
with_items:
|
||||
- PackageManagement
|
||||
- PowerShellGet
|
||||
|
||||
- name: update NuGet version
|
||||
when: powershell_major_version.stdout | int >= 5
|
||||
win_shell: |
|
||||
$nuget_exists = (Get-PackageProvider | Where-Object { $_.Name -eq 'Nuget' } | Measure-Object).Count -eq 1
|
||||
|
||||
if ( $nuget_exists ) {
|
||||
$nuget_outdated = (Get-PackageProvider -Name NuGet -ErrorAction Ignore).Version -lt [Version]"2.8.5.201"
|
||||
}
|
||||
|
||||
if ( -not $nuget_exists -or $nuget_outdated ) {
|
||||
Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force
|
||||
}
|
||||
|
||||
- name: unregister the repository
|
||||
win_shell: 'Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore'
|
||||
changed_when: false
|
||||
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore
|
||||
|
||||
- name: run all tests
|
||||
include_tasks: tests.yml
|
||||
- block:
|
||||
- name: run all tests
|
||||
include_tasks: tests.yml
|
||||
|
||||
always:
|
||||
- name: ensure test repo is unregistered
|
||||
win_shell: Unregister-PSRepository {{ repository_name | quote }} -ErrorAction Ignore
|
||||
|
|
|
@ -4,3 +4,5 @@ test/integration/targets/win_dsc/files/xTestDsc/1.0.0/xTestDsc.psd1
|
|||
test/integration/targets/win_dsc/files/xTestDsc/1.0.0/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
|
||||
test/integration/targets/win_dsc/files/xTestDsc/1.0.1/xTestDsc.psd1
|
||||
test/integration/targets/win_dsc/files/xTestDsc/1.0.1/DSCResources/ANSIBLE_xTestResource/ANSIBLE_xTestResource.psm1
|
||||
test/integration/targets/win_psmodule/files/module/template.psd1
|
||||
test/integration/targets/win_psmodule/files/module/template.psm1
|
||||
|
|
Loading…
Reference in a new issue