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 fails due to PackageManagement requiring NuGet #147

Open
mjiderhamn opened this issue Oct 6, 2020 · 12 comments
Open

win_psmodule fails due to PackageManagement requiring NuGet #147

mjiderhamn opened this issue Oct 6, 2020 · 12 comments

Comments

@mjiderhamn
Copy link

SUMMARY

win_psmodule fails due to PackageManagement requiring NuGet.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_psmodule

ANSIBLE VERSION
ansible 2.10.2
  config file = /cygdrive/l/sandbox/ip-infrastructure/ansible/ansible.cfg
  configured module search path = ['/home/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.10 (default, Jun  8 2020, 19:37:31) [GCC 9.3.0]
CONFIGURATION
ANSIBLE_SSH_ARGS(/cygdrive/redacted/ansible/ansible.cfg) = -o ForwardAgent=yes -o ControlMaster=no -o PasswordAuthentication=no
OS / ENVIRONMENT

Windows Server 2012 R2 Datacenter
PowerShell 5.1.14409.1018

STEPS TO REPRODUCE

Apply playbook

- name: Install PSCX
  win_psmodule:
    name: Pscx
    allow_clobber: yes
EXPECTED RESULTS

Module is installed

ACTUAL RESULTS

win_psmodule.ps1 has an Install-NugetProvider function to make sure NuGet provider is available, however it is called only after Import-Module -Name PackageManagement, PowerShellGet at line 427.

fatal: [my-host]: FAILED! => {
    "changed": false,
    "msg": "Problems adding a prerequisite module PackageManagement Exception calling \"ShouldContinue\" with \"2\" argument(s): \"A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\\Program Files\\PackageManagement\\ProviderAssemblies' or 'C:\\Users\\me\\AppData\\Local\\PackageManagement\\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?\"",
    "nuget_changed": false,
    "output": "foobar",
    "repository_changed": false
}
@Yannis100
Copy link

Workaround : add the following task before using win_psmodule
- ansible.windows.win_shell: Install-PackageProvider -Name Nuget -Force
or Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force

@J3ronimo
Copy link

Workaround : add the following task before using win_psmodule - ansible.windows.win_shell: Install-PackageProvider -Name Nuget -Force or Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force

Works for me! 👍 But does this re-install everytime?

@thewriteway
Copy link

thewriteway commented Nov 23, 2022

this is still broken on Ansible 6.6.0 with Ansible-core-2.13.6. Ansible V7 also had the same issue.

@gillg
Copy link

gillg commented Apr 4, 2023

Does anyone has a solution to make Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force idempotent ?
Any reason to not have it inside https://github.com/ansible-collections/community.windows/blob/main/plugins/modules/win_psmodule.ps1#L46 ?

@denysaqua
Copy link

If is set parameter required_version, Nuget not installed automatically, and I got error that the Nuget package is missing in the system.
Without required_version parameter, Nuget installed automatically, and everything works.

My module installation code:

- name: Install SQLServer PowerShell module
  community.windows.win_psmodule:
    name: SqlServer
    required_version: 21.1.18256
    state: present

@gillg
Copy link

gillg commented Apr 7, 2023

If is set parameter required_version, Nuget not installed automatically, and I got error that the Nuget package is missing in the system. Without required_version parameter, Nuget installed automatically, and everything works.

My module installation code:

- name: Install SQLServer PowerShell module
  community.windows.win_psmodule:
    name: SqlServer
    required_version: 21.1.18256
    state: present

I very recently used maximum_version instead of required_version for the exact same module (sqlserver) and it was fine.
Can you test or attach some logs ?

@denysaqua
Copy link

With maximum_version I got a same error as with required_version parameter.
At now I using this workeround method:
#147 (comment)

ANSIBLE VERSION

ansible [core 2.13.7]
  config file = None
  configured module search path = ['/home/vscode/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /home/vscode/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

OS / ENVIRONMENT
Windows Server 2019 Datacenter
PSVersion 5.1.17763.3770
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.3770
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

ERROR LOG

The full traceback is:
Exception calling "ShouldContinue" with "2" argument(s): "A command that prompts the user failed because the host 
program or the command type does not support user interaction. The host was attempting to request confirmation with the 
following message: PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based 
repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 
'C:\Users\DefaultUser\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider 
by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install 
and import the NuGet provider now?"
At line:131 char:13
+             $null = $job | Receive-Job -AutoRemoveJob -Wait -ErrorAct ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-NuGetClientBinaries], MethodInvocationException
    + FullyQualifiedErrorId : HostException,Install-NuGetClientBinaries
 

at Install-NuGetClientBinaries, C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1: line 7455
at Install-Module<Begin>, C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1: line 1762
at <ScriptBlock>, <No file>: line 26
fatal: [127.0.0.1]: FAILED! => {
    "changed": true,
    "msg": "Problems adding a prerequisite module PackageManagement or PowerShellGet: Exception calling \"ShouldContinue\" with \"2\" argument(s): \"A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\\Program Files\\PackageManagement\\ProviderAssemblies' or 'C:\\Users\\DefaultUser\\AppData\\Local\\PackageManagement\\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?\"",
    "nuget_changed": false,
    "output": "",
    "repository_changed": false
}

@RudolfAchter
Copy link

If it helps. With the PackageProvider Idempodency Case i do the following

- name: Make Nuget Package Provider exist
  ansible.windows.win_powershell:
    script: "{{ lookup('file', 'files/Install-PackageProvider-NuGet.ps1') }}"
  register: powershell_result

- name: Debug powershell_result
  ansible.builtin.debug:
    var: powershell_result
  • Install-PackageProvider-NuGet.ps1
if($null -eq $Ansible){
    $Ansible = @{}
}

$pProv=Get-PackageProvider | Where-Object{$_.Name -eq "NuGet"}

if($null -ne $pProv){
    $Ansible.Changed = $false
    # OK
    return
}
else{
    $pProv=$null
    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
    $Ansible.Changed = $true
    $pProv=Get-PackageProvider | Where-Object{$_.Name -eq "NuGet"}
    if($null -ne $pProv){
        # OK
    }
    else{
        $Ansible.Failed=$true
    }
}

@scaronni
Copy link

@RudolfAchter worked like a charm! thanks.

@egerlach
Copy link

Is anyone working on a fix for this? Asking so I don't duplicate work. This seems like an easy fix. Can't guarantee I'll have time but if I do I might give it a shot.

@derSchweiger
Copy link

Issue is still valid.

@coty-terumo
Copy link

coty-terumo commented Mar 11, 2024

Started happening today when I needed to use the accept_license parameter

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

No branches or pull requests