ansible-collections / community.windows

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

win_psmodule for PowerShellGet error: A parameter cannot be found that matches parameter name 'AcceptLicense' in 1.12.0 #487

Closed AlbMor closed 1 year ago

AlbMor commented 1 year ago
SUMMARY

In 1.12.0 win_psmodule is throwing the error:Problems installing PowerShellGet module: A parameter cannot be found that matches parameter name 'AcceptLicense'.

Before running the Ansible this is the status of the Host

PS C:\Windows\system32> Get-Module -Name PowerShellGet -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

The first run of the configuration is failing with

fatal: [ansibleHost]: FAILED! => {
    "changed": true,
    "msg": "Problems installing PowerShellGet module: A parameter cannot be found that matches parameter name 'AcceptLicense'.",
    "nuget_changed": false,
    "output": "",
    "repository_changed": false
}

But the Mudule is actually installed

Status on the Host

PS C:\Windows\system32> Get-Module -Name PowerShellGet -ListAvailable

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

The rerun is actually going ok and result is

changed: [ansibleHost] => {
    "changed": true,
    "nuget_changed": false,
    "output": "Module PowerShellGet installed",
    "repository_changed": false
}

If I run installing the PowerShellGet version 2.2.5 instead of the 2.2.1 then is working fine

I don´t know if due to PowerShellGet or Ansible

ISSUE TYPE
COMPONENT NAME

win_psmodule

ANSIBLE VERSION
COLLECTION VERSION
ansible [core 2.14.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.9 (main, Dec 12 2022, 17:52:15) [GCC 12.2.1 20220924] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
CONFIGURATION
OS / ENVIRONMENT

Ansible Master running in Win11 22H2 with Docker image Configuration applied to Host Vagrant Box running Win11 22H2

STEPS TO REPRODUCE
- name: Add PowerShellGet module
  win_psmodule:
    name: PowerShellGet
    required_version: '2.2.1'
    state: present
    accept_license: false
EXPECTED RESULTS
ACTUAL RESULTS

The PowerShellGET module is installed but we get the error

fatal: [ansibleHost]: FAILED! => {
    "changed": true,
    "msg": "Problems installing PowerShellGet module: A parameter cannot be found that matches parameter name 'AcceptLicense'.",
    "nuget_changed": false,
    "output": "",
    "repository_changed": false
}
jborean93 commented 1 year ago

Thanks for reporting this, it took a while to figure out why it was happening but it will be fixed with https://github.com/ansible-collections/community.windows/pull/488.