mwrock / packer-templates

Templates for creating vagrant boxes
Other
535 stars 250 forks source link

Win2016 HyperV - No Search Match For NuGet #127

Closed bp-rocket closed 4 years ago

bp-rocket commented 4 years ago

Packer/Chef noob here. Please excuse my ignorance.

This packer.exe call from a Powershell session fails…

.\packer build -force -only hyperv-iso hyperv-2016.json

The following output suggests a problem installing the NuGet package due to the missing tags ‘PackageManagement’ and ‘Provider’. Assuming this is the root cause, can someone assist me in resolving the problem?

hyperv-iso: Recipe: packer-templates::install_ps_modules hyperv-iso: * powershell_script[install Nuget package provider] action run hyperv-iso: hyperv-iso: ================================================================================ hyperv-iso: Error executing action run on resource ‘powershell_script[install Nuget package provider]’ hyperv-iso: ================================================================================ hyperv-iso: hyperv-iso: Mixlib::ShellOut::ShellCommandFailed hyperv-iso: ------------------------------------ hyperv-iso: Expected process to exit with [0], but received ‘1’ hyperv-iso: ---- Begin output of “C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File “C:/Users/vagrant/AppData/Local/Temp/chef-script20200629-2796-10d960z.ps1” ---- hyperv-iso: STDOUT: WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «» hyperv-iso: WARNING: Unable to download the list of available providers. Check your internet connection. hyperv-iso: WARNING: Unable to download from URI ‘https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409’ to ‘’. hyperv-iso: STDERR: No match was found for the specified search criteria for the provider ‘NuGet’. The package provider requires ‘PackageManagement’ and ‘Provider’ tags. Please check if the specified package has the tags. hyperv-iso: ---- End output of “C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File “C:/Users/vagrant/AppData/Local/Temp/chef-script20200629-2796-10d960z.ps1” ---- hyperv-iso: Ran “C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe” -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None -File “C:/Users/vagrant/AppData/Local/Temp/chef-script20200629-2796-10d960z.ps1” returned 1 hyperv-iso: hyperv-iso: Resource Declaration: hyperv-iso: --------------------- hyperv-iso: # In c:/windows/temp/packer-chef-solo/local-mode-cache/cache/cookbooks/packer-templates/recipes/install_ps_modules.rb hyperv-iso: hyperv-iso: 1: powershell_script ‘install Nuget package provider’ do hyperv-iso: 2: code ‘Install-PackageProvider -Name NuGet -Force’ hyperv-iso: 3: not_if ‘(Get-PackageProvider -Name Nuget -ListAvailable -ErrorAction SilentlyContinue) -ne $null’ hyperv-iso: 4: end hyperv-iso: 5: hyperv-iso: hyperv-iso: Compiled Resource: hyperv-iso: ------------------ hyperv-iso: # Declared in c:/windows/temp/packer-chef-solo/local-mode-cache/cache/cookbooks/packer-templates/recipes/install_ps_modules.rb:1:in `from_file’ hyperv-iso: hyperv-iso: powershell_script(“install Nuget package provider”) do hyperv-iso: action [:run] hyperv-iso: default_guard_interpreter :powershell_script hyperv-iso: backup 5 hyperv-iso: interpreter “powershell.exe” hyperv-iso: declared_type :powershell_script hyperv-iso: cookbook_name “packer-templates” hyperv-iso: recipe_name “install_ps_modules” hyperv-iso: code “Install-PackageProvider -Name NuGet -Force” hyperv-iso: domain nil hyperv-iso: user nil hyperv-iso: flags “-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -InputFormat None” hyperv-iso: not_if “(Get-PackageProvider -Name Nuget -ListAvailable -ErrorAction SilentlyContinue) -ne $null” hyperv-iso: end hyperv-iso: hyperv-iso: System Info: hyperv-iso: ------------ hyperv-iso: chef_version=16.2.50 hyperv-iso: platform=windows hyperv-iso: platform_version=10.0.14393 hyperv-iso: ruby=ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32] hyperv-iso: program_name=c:/opscode/chef/bin/chef-solo hyperv-iso: executable=c:/opscode/chef/bin/chef-solo

mwrock commented 4 years ago

Most likely this is due to the fact that nuget is no longer supporting tls 1.0 and 1.1. You need to enable 1.2 which is not the default on 2016. Have a look at https://devblogs.microsoft.com/nuget/deprecating-tls-1-0-and-1-1-on-nuget-org/

bp-rocket commented 4 years ago

Thank you mwrock.

Pardon my ignorance, but if the process of generating the VM fails, how does one enable TLS 1.2 during the generation process?

Is there a flag somewhere I can set? Is there a way to pause the generation process to enable TLS 1.2 in the VM? Am I missing something?

mwrock commented 4 years ago

Basically before interacting with nuget you can run [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bOR [Net.SecurityProtocolType]::Tls12 which will enable it for the current shell. You can also set it permanently in the registry. The above link has the code to do that.

bp-rocket commented 4 years ago

This adjustment to the install_ps_modules.rb file solved my problem. It is probably overkill in the loop, but my ignorance doesn't allow me to make it more efficient. Thanks again mwrock.

`powershell_script 'install Nuget package provider' do code <<~SCRIPT

Install-PackageProvider -Name NuGet -Force

SCRIPT not_if '(Get-PackageProvider -Name Nuget -ListAvailable -ErrorAction SilentlyContinue) -ne $null' end

%w{PSWindowsUpdate xNetworking xRemoteDesktopAdmin xCertificate}.each do |ps_module| powershell_script "install #{ps_module} module" do code <<~SCRIPT

    Install-Module #{ps_module} -Force
SCRIPT
not_if "(Get-Module #{ps_module} -list) -ne $null"

end end`