mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
New module: Add module to install/remove/register/unregiser windows powershell modules (windows/win_psmodule) (#23604)
* Add new windows module win_psmodule * Add checkmode, allow_clobber parameter, integration tests * Add aliases, replace win_raw with win_shell * restore original test_win_group1.yml, add powershel version test * fix var type * add conditional on assert * integration tests conditional tasks review * documentation fix, test fix, adds result.change * fix yml * fix railing whitespace * add nuget_changed and repository_changed in result
This commit is contained in:
parent
1e8c58519e
commit
9d932b64f0
6 changed files with 465 additions and 0 deletions
1
test/integration/targets/win_psmodule/aliases
Normal file
1
test/integration/targets/win_psmodule/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group1
|
5
test/integration/targets/win_psmodule/defaults/main.yml
Normal file
5
test/integration/targets/win_psmodule/defaults/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
|
||||
powershell_module: powershell-yaml
|
||||
wrong_module: powershell_yaml
|
||||
allow_clobber_module: PowerShellCookbook
|
28
test/integration/targets/win_psmodule/tasks/main.yml
Normal file
28
test/integration/targets/win_psmodule/tasks/main.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
# test code for the win_psmodule module when using winrm connection
|
||||
# (c) 2017, Daniele Lazzari <lazzari@mailup.com>
|
||||
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
- name: get facts
|
||||
setup:
|
||||
|
||||
- name: Perform integration tests for Powershell 5+
|
||||
when: ansible_powershell_version >= 5
|
||||
block:
|
||||
|
||||
- name: run all tasks
|
||||
include: test.yml
|
136
test/integration/targets/win_psmodule/tasks/test.yml
Normal file
136
test/integration/targets/win_psmodule/tasks/test.yml
Normal file
|
@ -0,0 +1,136 @@
|
|||
---
|
||||
|
||||
- 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|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:
|
||||
- "not module_reinstall|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|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|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|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|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|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:
|
||||
- "not module_uninstall_2|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:
|
||||
- "not module_uninstall_2|changed"
|
||||
- "module_uninstall_3|changed"
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue