Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_psmodule needs to address -AcceptLicense parameter #340

Closed
ghost opened this issue Nov 19, 2021 · 16 comments · Fixed by #411
Closed

win_psmodule needs to address -AcceptLicense parameter #340

ghost opened this issue Nov 19, 2021 · 16 comments · Fixed by #411

Comments

@ghost
Copy link

ghost commented Nov 19, 2021

SUMMARY

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

ISSUE TYPE
  • Feature Idea
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
Copy link
Contributor

briantist commented Jul 4, 2022

@davidsampson-hv
Copy link

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

@thewriteway
Copy link

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
Copy link

y-melo commented Dec 26, 2022

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
Copy link

jsw1993 commented Jan 7, 2023

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

@waddelb2
Copy link

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

@AlbMor
Copy link

AlbMor commented Feb 2, 2023

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
Copy link

thewriteway commented Feb 2, 2023

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

@Marmeus
Copy link

Marmeus commented Feb 21, 2023

Same for me, it is not working anymore

@jborean93
Copy link
Collaborator

Has been fixed with #488 and will be present in the next release.

@Marmeus
Copy link

Marmeus commented Feb 21, 2023

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
Copy link

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
Copy link

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
Copy link

jantari commented Jul 4, 2023

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
Copy link

waddelb2 commented Sep 11, 2023

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
Copy link

gabrielgbs97 commented Sep 16, 2024

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 win_psmodule module. is not honored, or something happened after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.