diff options
Diffstat (limited to 'test/integration/targets/win_psmodule/tasks/test.yml')
-rw-r--r-- | test/integration/targets/win_psmodule/tasks/test.yml | 143 |
1 files changed, 28 insertions, 115 deletions
diff --git a/test/integration/targets/win_psmodule/tasks/test.yml b/test/integration/targets/win_psmodule/tasks/test.yml index b74ab4fa64..5e33675d61 100644 --- a/test/integration/targets/win_psmodule/tasks/test.yml +++ b/test/integration/targets/win_psmodule/tasks/test.yml @@ -1,20 +1,24 @@ --- - -- name: install module from Powershell Gallery +- name: install module win_psmodule: - name: "{{ powershell_module }}" + name: ansible-test1 state: present register: module_setup +- name: test that module is installed + win_shell: Import-Module -Name ansible-test1; Get-AnsibleTest1 | ConvertTo-Json + register: module_setup_actual + - name: test Powershell Gallery module setup assert: that: - "module_setup is changed" - - "module_setup.output == 'Module {{ powershell_module }} installed'" + - "module_setup.output == 'Module ansible-test1 installed'" + - module_setup_actual.stdout | from_json == {"Name":"ansible-test1","Version":"1.0.0","Repo":"PSRepo 1"} - name: check idempotency reinstalling module win_psmodule: - name: "{{ powershell_module }}" + name: ansible-test1 state: present register: module_reinstall @@ -25,7 +29,7 @@ - name: check module install with allow_clobber not active win_psmodule: - name: "{{ allow_clobber_module }}" + name: ansible-clobber register: fail_allow_clobber ignore_errors: yes @@ -36,18 +40,23 @@ - name: check module install with allow_clobber active win_psmodule: - name: "{{ allow_clobber_module }}" + name: ansible-clobber allow_clobber: yes register: ok_allow_clobber +- name: get result of install with allow_clobber active + win_shell: Import-Module -Name ansible-clobber; Enable-PSTrace | ConvertTo-Json + register: ok_allow_clobber_actual + - name: test module install with allow_clobber active assert: that: - "ok_allow_clobber is changed" + - ok_allow_clobber_actual.stdout | from_json == {"Name":"ansible-clobber","Version":"1.0.0","Repo":"PSRepo 1"} - name: check wrong module install attempt - win_psmodule: - name: "{{ wrong_module }}" + win_psmodule: + name: fake_module state: present ignore_errors: yes register: module_fail @@ -59,7 +68,7 @@ - name: check fake custom ps repository registration attempt win_psmodule: - name: "{{ wrong_module }}" + name: fake_module repository: Fake repository url: http://my_fake_repo.com/repo/ ignore_errors: yes @@ -70,48 +79,26 @@ 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 + name: ansible-test1 state: absent register: module_uninstall +- name: get result of remove installed powershell module + win_shell: (Get-Module -ListAvailable -Name ansible-test1 | Measure-Object).Count + register: module_uninstall_actual + - 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 == ''" + - "module_uninstall.output == 'Module ansible-test1 removed'" + - module_uninstall_actual.stdout | trim | int == 0 - name: check idempotency re-removing module win_psmodule: - name: "{{ powershell_module }}" + name: ansible-test1 state: absent register: module_uninstall_2 @@ -122,7 +109,7 @@ - name: check removing allow_clobber module win_psmodule: - name: "{{ allow_clobber_module }}" + name: ansible-clobber state: absent register: module_uninstall_3 @@ -131,77 +118,3 @@ 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 -EA SilentlyContinue; - Import-PackageProvider -Name $psg.n -RequiredVersion $psg.v -EV 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 -EA 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 "$repoPath\\*" | ? Name -match "$modName.*.nupkg" | % 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" |