Repository navigation
psrepository fails after initial corrective action #32
Description
Activity
was there a fix for this?
@bishopbm1 or @gsperry2011 can you guys look into this? i don't have Windows anymore to check it out.
I will provide a lot of information: I am on windows2016 server core:
"${env:ProgramFiles}\PackageManagement\ProviderAssemblies\Microsoft.PackageManagement.NuGetProvider.dll
is presentMy error is:
Could not set 'present' on ensure: Error when executing command: $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; $params = @{ Name = 'psgallery-virtual' SourceLocation = 'https://chocolatey.example.com/chocolatey' InstallationPolicy = 'trusted' } # Detecting if this is Powershell Gallery repo or not if ($params.Name -eq 'PSGallery' -or $params.SourceLocation -match 'powershellgallery') { # Trim these params or the splatting will fail $params.Remove('Name') $params.Remove('SourceLocation') Register-PSRepository -Default @params } else { # For all non-PSGallery repos.. Register-PSRepository @params } stdout = stderr = [] (file: /etc/puppetlabs/code/environments/master/modules/os/manifests/powershell.pp, line: 3)This only happens on a handful of nodes, so it is not consistent.
Contents of PSRepositories.xml in the c$\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"> <Obj RefId="0"> <TN RefId="0"> <T>System.Collections.Hashtable</T> <T>System.Object</T> </TN> <DCT> <En> <S N="Key">psgallery-virtual</S> <Obj N="Value" RefId="1"> <TN RefId="1"> <T>Microsoft.PowerShell.Commands.PSRepository</T> <T>System.Management.Automation.PSCustomObject</T> <T>System.Object</T> </TN> <MS> <S N="Name">psgallery-virtual</S> <S N="SourceLocation">https://chocolatey.example.com/chocolatey</S> <Nil N="PublishLocation" /> <Nil N="ScriptSourceLocation" /> <Nil N="ScriptPublishLocation" /> <B N="Trusted">true</B> <B N="Registered">true</B> <S N="InstallationPolicy">Trusted</S> <S N="PackageManagementProvider">NuGet</S> <Obj N="ProviderOptions" RefId="2"> <TNRef RefId="0" /> <DCT /> </Obj> </MS> </Obj> </En> </DCT> </Obj> </Objs>
psrepository { 'psgallery-virtual': ensure => present, source_location => 'https://chocolatey.example.com/chocolatey', installation_policy => 'trusted', }
sanitized domain names
What's the output look like if you run this in powershell (please make sure it's "run as administrator"), also please change the
$paramsto match whatever you have specified in hiera.$ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; $params = @{ Name = 'psgallery-virtual' SourceLocation = 'https://chocolatey.example.com/chocolatey' InstallationPolicy = 'trusted' } # Detecting if this is Powershell Gallery repo or not if ($params.Name -eq 'PSGallery' -or $params.SourceLocation -match 'powershellgallery') { # Trim these params or the splatting will fail $params.Remove('Name') $params.Remove('SourceLocation') # debug statement write-host "is PSrepo" Register-PSRepository -Default @params } else { # debug statement write-host "NOT a PSrepo" # For all non-PSGallery repos.. Register-PSRepository @params }unregister-psrepository psgallery-virtual.
run above:
NOT a PSrepo.Rerun:
NOT a PSrepo
PackageManagement\Register-PackageSource : Module Repository 'psgallery-virtual' exists.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11587 char:17- ... $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : ResourceExists: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-PackageSource], Exception
- FullyQualifiedErrorId : PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
Hello,
I added a try - catch on the block "create_command" when it tries to "Register-PSRepository @params" in lib\puppet\provider\psrepository\powershellcore.rb as the error seems to come from the fact that the repository is tried to be re-added if it exists already.
Another weird behavior I noticed is that the stdout from the "self.instances_command" block is not returning anything.
I found that the repository discovery block "self.instances_command" was not generating any return at first run, seems like it's due to the
-WarningAction Stop. If the WarningAction behavior is set to Ignore, as warnings comming fromGet-PSRepositoryon first run can be ignored, it generates an output and the error disappear.So far it fixed the issue and seems a better solution than adding a try catch block as stated earlier.
cheers
Hi,
I ran into an issue while checking psrepository after it has been created successfully at first puppet run. We run an offline environment.
Side note:
The NuGet package provider has been installed manually before (copy Microsoft.PackageManagement.NuGetProvider.dll) and can't be checked successfully via pspackageprovider:
Back to topic:
Our used modules:
hiera-config:
Output of puppet run:
The corrective action can be verified successfully in a new PowerShell-session:
Any help is much appreciated :)
Regards,
Norbert