ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
199 stars 152 forks source link

Ansible community.windows.win_psrepository throwing PSGet req but it is already met #376

Open iasllanih opened 2 years ago

iasllanih commented 2 years ago
SUMMARY

win_psrepository throwing error fatal: [molecule--windows-base-role-srv19-01]: FAILED! => { "changed": false, "msg": "PowerShellGet version 1.6.0+ is required." }

(his does not happen on ansible 2.9 (We are trying to upgrade)

ISSUE TYPE
COMPONENT NAME

community.windows.win_psrepository

ANSIBLE VERSION
ansible [core 2.12.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/ansible/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/ansible/bin/ansible
  python version = 3.8.5 (default, Aug 27 2020, 18:15:13) [GCC 7.3.1 20180712 (Red Hat 7.3.1-9)]
  jinja version = 3.1.1
  libyaml = True
COLLECTION VERSION
bash-4.2# ansible-galaxy collection list community.windows

# /opt/ansible/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.windows 1.9.0
CONFIGURATION
OS / ENVIRONMENT

Windows 2016 public AMI

STEPS TO REPRODUCE

Run the module

    - name: InternalPSGallery - setup repository
      win_psrepository:
        name: InternalPSGallery
        source: "{{ ps_gallery_powershell_repository }}"
        state: present
EXPECTED RESULTS

Powershell repo to be configured

ACTUAL RESULTS

Error complaining about powershellget version not being 1.6.0+, but it is ` PS C:\Windows\system32> Find-Module -Name PowerShellGet

Version Name Repository Description


2.2.5 PowerShellGet PSGallery PowerShell module with commands for discovering,... `

Not only does this module work perfectly fine in 2.9, i can manually add the repo as well.


    task path: /opt/ansible/roles/hs_role_base_windows/tasks/powershell_repository.yml:28
    redirecting (type: modules) ansible.builtin.win_psrepository to community.windows.win_psrepository
    Using module file /opt/ansible/lib/python3.8/site-packages/ansible_collections/community/windows/plugins/modules/win_psrepository.ps1
    Pipelining is enabled.
    <> ESTABLISH WINRM CONNECTION FOR USER: molecule on PORT 5986 TO 
    EXEC (via pipeline wrapper)

    PLAY RECAP *********************************************************************
    molecule--windows-base-role-srv19-01 : ok=22   changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0

fatal: [molecule--windows-base-role-srv19-01]: FAILED! => {
    "changed": false,
    "msg": "PowerShellGet version 1.6.0+ is required."
}
ERROR:
jborean93 commented 2 years ago

AFAIK Find-Module will be used to find modules on a remote repository not tell you what is installed. You want Get-Module -Name PowerShellGet -ListAvailable to see what is installed. PowerShellGet is installed by default but you may need to update it to support newer features the module relies on.

iasllanih commented 2 years ago

AFAIK Find-Module will be used to find modules on a remote repository not tell you what is installed. You want Get-Module -Name PowerShellGet -ListAvailable to see what is installed. PowerShellGet is installed by default but you may need to update it to support newer features the module relies on.

Thanks for the tip... strange thing is, why was it working on Ansible 2.9 with no error?

Thanks!

iasllanih commented 2 years ago

And im using the same ami and running the exact same role, so the image itself is not any different

clcaldwell commented 2 years ago

Just looked at it - that module isn't doing anything special, it is just calling the Import-Module command, as such: if (-not (Import-Module -Name PowerShellGet -MinimumVersion 1.6.0 -PassThru -ErrorAction SilentlyContinue)) { Fail-Json -obj $result -Message "PowerShellGet version 1.6.0+ is required." }

@iasllanih If you want to troubleshoot, run Import-Module -Name PowerShellGet -MinimumVersion 1.6.0 -PassThru on the server you are having issues with - should hopefully give you a better idea of what is going on. Either way, if it is a bug, it is likely a bug with the Import-Module command, and not with the community.windows.win_psrepository module.

@jborean93 Should we add PS error details to the output? Like:

if (-not (Import-Module -Name PowerShellGet -MinimumVersion 1.6.0 -PassThru -ErrorAction SilentlyContinue -ErrorVariable moduleErr)) {
    Fail-Json -obj $result -Message "PowerShellGet version 1.6.0+ is required. $($moduleErr.Exception)"
}
kpavon-silex commented 5 months ago

Ran into the same issue and did a comparison.

In Ansible 2.9, ansible.windows.win_psrepository.ps1 does not have this check as it was not a requirement at that time. While base functionality still works, the upgraded PowerShellGet adds additional functionality which is required by features since added. As such this is not a bug, but a change in requirements.

ibre5041 commented 2 months ago

Just out of curiosity what is intended use area for this module? Windows server 2022 by default comes with PowerShell 5.1 so it does now meet requirements:

Do I have to install PowerShell 7 on mine Windows servers, or do I have to upgrade these modules manually, before I can orchestrate them using Ansible? How others overcome there requirements on their servers?