mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
809 lines
34 KiB
YAML
809 lines
34 KiB
YAML
|
# 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
|