2019-03-05 21:56:55 +01:00
|
|
|
# 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)
|
|
|
|
|
2017-06-26 23:01:38 +02:00
|
|
|
---
|
|
|
|
|
2019-03-05 21:56:55 +01:00
|
|
|
# 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.
|
|
|
|
|
2017-06-26 23:01:38 +02:00
|
|
|
- name: install module from Powershell Gallery
|
|
|
|
win_psmodule:
|
|
|
|
name: "{{ powershell_module }}"
|
|
|
|
state: present
|
|
|
|
register: module_setup
|
|
|
|
|
|
|
|
- name: test Powershell Gallery module setup
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_setup is changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
- "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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_reinstall is not changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- 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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "fail_allow_clobber is failed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- 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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "ok_allow_clobber is changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- name: check wrong module install attempt
|
2019-03-05 21:56:55 +01:00
|
|
|
win_psmodule:
|
2017-06-26 23:01:38 +02:00
|
|
|
name: "{{ wrong_module }}"
|
|
|
|
state: present
|
|
|
|
ignore_errors: yes
|
|
|
|
register: module_fail
|
|
|
|
|
|
|
|
- name: test module setup fails
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_fail is failed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- 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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "repo_fail is failed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- 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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_uninstall is changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
- "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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_uninstall_2 is not changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
|
|
|
- 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:
|
2017-11-27 23:58:08 +01:00
|
|
|
- "module_uninstall_2 is not changed"
|
|
|
|
- "module_uninstall_3 is changed"
|
2017-06-26 23:01:38 +02:00
|
|
|
|
2018-05-22 23:36:57 +02:00
|
|
|
- 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
|
2019-03-05 21:56:55 +01:00
|
|
|
$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
|
2018-05-22 23:36:57 +02:00
|
|
|
|
|
|
|
if($missingProvider){
|
2019-03-05 21:56:55 +01:00
|
|
|
Install-PackageProvider -Name $psg.n -RequiredVersion $psg.v -Confirm:$false -Force | Out-Null
|
|
|
|
|
2018-05-22 23:36:57 +02:00
|
|
|
# Unload previous version
|
2019-03-05 21:56:55 +01:00
|
|
|
Remove-Module -Name $psg.n -Force -ErrorAction SilentlyContinue;
|
|
|
|
Import-PackageProvider -Name $psg.n -RequiredVersion $psg.v -Force | Out-Null
|
2018-05-22 23:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 21:56:55 +01:00
|
|
|
$modName = "{{powershell_module}}"
|
|
|
|
$temp = $env:Temp
|
2018-05-22 23:36:57 +02:00
|
|
|
|
2019-03-05 21:56:55 +01:00
|
|
|
Save-Module -Name $modName -Repository PSGallery -Path $temp | Out-Null
|
2018-05-22 23:36:57 +02:00
|
|
|
|
2019-03-05 21:56:55 +01:00
|
|
|
$repoName = "{{custom_repo_name}}"
|
|
|
|
$repoPath = "{{custom_repo_path}}"
|
2018-05-22 23:36:57 +02:00
|
|
|
|
|
|
|
if(!(Test-Path $repoPath)){
|
2019-03-05 21:56:55 +01:00
|
|
|
New-Item -Type Directory $repoPath -Force | Out-Null
|
2018-05-22 23:36:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-05 21:56:55 +01:00
|
|
|
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 }
|
|
|
|
|
2018-05-22 23:36:57 +02:00
|
|
|
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"
|