mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
test: optimize win_psmodule tests (#53431)
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user