ansible-collections / community.windows

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

win_psmodule needs to address -AcceptLicense parameter #340

Closed ghost closed 2 years ago

ghost commented 2 years ago
SUMMARY

Support the AcceptLicense parameter for the Install-Module powershell cmdlet used by win_psmodule's Install-PsModule function.

ISSUE TYPE
COMPONENT NAME

win_psmodule -> Function Install-PsModule

ADDITIONAL INFORMATION

There are some PowerShell modules that require the -AcceptLicense parameter to be passed to Install/Update-Module. For example, the HPCMSL module has a dependent module HP.Private that will not install without passing this parameter and returns an error.

This could be handled by adding an optional parameter to the win_psmodule, or by automatically applying it in the Install-PsModule function. I think best practice should be to add it as a boolean option to win_psmodule and default to false. This would be consistent retroactively with existing playbooks, and would help document when the parameter is required.

- community.windows.win_psmodule:
    name: HPCMSL
    state: latest
    acceptlicense: true
briantist commented 2 years ago

Some additional relevant info: https://docs.microsoft.com/en-us/powershell/scripting/gallery/concepts/module-license-acceptance?view=powershell-5.1

davidsampson-hv commented 2 years ago

This has caused a breaking change as not all PS modules accept the -acceptlicense parameter such as the FailoverClusterDSC module.

thewriteway commented 1 year ago

I still get a parameter error on when trying to execute the module.

I see in your example its listed as acceptlicense and not accept_license , was that a typo?

y-melo commented 1 year ago

I was getting the same error, I had to add skip_publishe_check: true, not sure if is about the security of using this but it worked:

- name: Install Nuget (for Pscx)
  win_psmodule:
    name: NuGet
    accept_license: true
    skip_publisher_check: true
    state: present
jsw1993 commented 1 year ago

Agree this is a breaking change 😟. This parameter should be optional as not all modules support.

waddelb2 commented 1 year ago

I'm still having the issue of modules randomly reporting "cannot be found that matches parameter name 'AcceptLicense'."

AlbMor commented 1 year ago

same here. The installation of the PowerShellGet with the win_psmodule reports randomly

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 }

Ansible version

ansible-playbook [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-playbook 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

thewriteway commented 1 year ago

Can this issue be reopened. It's no longer working correctly with the license parameters. @jborean93

Marmeus commented 1 year ago

Same for me, it is not working anymore

jborean93 commented 1 year ago

Has been fixed with https://github.com/ansible-collections/community.windows/pull/488 and will be present in the next release.

Marmeus commented 1 year ago

That is great news, great job.

Do you know when is going to be released?

I have tried on 1.12.0 and still doesn't work. image

saravanansuraj commented 1 year ago

Hi, I am new to ansible but I am also having the same issue. but 1 thing I would like to add here

this module only fails the first time we try in a new server but the secon time this works as expected attaching the screen shot for reference

image

ThePowershellNinja commented 1 year ago

I just ran into this problem. The Install-Module Cmdlet is available on all servers that have Windows Powershell 5.1. However, the Cmdlet is in the PowerShellGet Module and is at version 1.0.0.1 by default, which does not have a parameter for -AcceptLicense. That parameter only becomes available once you update the PowerShellGet module (although I am not sure what version the parameter is introduced in).

To work around this issue, I ran a win_shell beforehand to specifically ensure this module is updated so that win_psmodule works as expected for all the other modules.

    - name: Install Latest Version of PowershellGet
      ansible.windows.win_shell: |
        $ErrorActionPreference = 'Stop'
        Install-Module -Name 'PowerShellGet' -Repository 'PSGallery' -Scope 'AllUsers' -AllowClobber -Force -Confirm:$false
jantari commented 1 year ago

Even Windows Server 2022 still ships with PowerShellGet version 1.0.0.1 and is affected by this issue.

Looks like the best course of action is pre-installing a newer version of PowerShellGet in our VM templates...

waddelb2 commented 1 year ago

So I installed the latest version of the community.windows collection (2.0), but I believe my Ansible isn't using it because an "ansible-galaxy collection list" is showing 3 different community.windows installed in 3 different locations. How to I make Ansible exclusively use 2.0?

gabrielgbs97 commented 1 month ago

I run this before installing required PS Modules:

- name: Install NuGet if necessary
  ansible.windows.win_shell: |
    $providers = (Get-PackageProvider | Where-Object -Property Name -Match nuget)
    if ($providers -eq $null) {
      Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope AllUsers
    }
  changed_when: False

# See https://github.com/ansible-collections/community.windows/issues/340
- name: Install upgraded PowershellGet if necessary
  ansible.windows.win_shell: |
    $module = Get-Module -ListAvailable -Name 'PowerShellGet' | Sort-Object -Property Version -Descending | Select-Object -First 1
    if ($module -eq $null -or $module.Version -le [Version]'1.0.0.1') {
        Install-Module -Name 'PowerShellGet' -Repository 'PSGallery' -Scope 'AllUsers' -AllowClobber -Force -Confirm:$false
    }
  changed_when: False

# EXAMPLE
- name: Install or update an existing PSWindowsUpdate module to the newest version
  community.windows.win_psmodule:
    name: PSWindowsUpdate
    state: latest
    accept_license: True

Also check your $env:PSModulePath. We have found that Microsoft Entra Connect Hosts mangle this variable...

To my mind, this issue is still a bug. I understand that _On PowerShell 5.x required modules and a package provider will be updated under the first run of the winpsmodule module. is not honored, or something happened after.