Git Product home page Git Product logo

puppet-powershellmodule's Issues

Provider import not working for Powershell Core on Windows?

Does this module work on Windows for Powershell Core packages as well?

Any idea what could cause this?

Error: Could not autoload puppet/provider/package/powershellcore: cannot load such file -- C:/ProgramData/PuppetLabs/puppet/var/lib/puppet_x/encore/powershellmodule/helper.rb
Error: Failed to apply catalog: Parameter provider failed on Package[AzureAD]: Could not autoload puppet/provider/package/powershellcore: cannot load such file -- C:/ProgramData/PuppetLabs/puppet/var/lib/puppet_x/encore/powershellmodule/helper.rb

Puppet version: 7.24
Powershell 7.2

Support TLS 1.2

The PowerShell Gallery has disabled anything < TLS 1.2. The problem with the previous psmodule was that it didn't support that so, assuming this hasn't been added as yet, this would be the first thing to add to get it working.

Convert module over to ruby-pwsh

ruby-pwsh has proved to be a huge time saver in some of our other modules, we should convert this one over to use that library and take advantage of cached powershell runtimes!

Request: Add support for downloading preview modules

Currently not supported to download preview modules from powershell gallery as there is no AllowPrerelease parameter

Install-Module : The '-AllowPrerelease' parameter must be specified when using the Prerelease string in MinimumVersion, MaximumVersion, or RequiredVersion

All preview powershell modules version name are named preview (eg. Name = ComputerManagementDsc, Version = 8.5.0-preview0001)

psrepository fails after initial corrective action

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:

Error: Could not prefetch pspackageprovider provider 'windowspowershell': 765: unexpected token at 'WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»'
Error: Failed to apply catalog: 765: unexpected token at 'WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»'

Back to topic:

Our used modules:

mod 'puppetlabs-dsc_lite', '3.1.0'
mod 'puppetlabs-pwshlib', '0.8.0'
mod 'encore-powershellmodule', '2.2.1'

hiera-config:

profile::powershell::psrepository:
  'PowerShell_DEV':
    ensure:                     present
    source_location:      'https://hostname.domain/nuget/PowerShell_DEV'
    installation_policy:  'trusted'
    provider:                  'windowspowershell'

Output of puppet run:

PS C:\> puppet agent -t
Info: Using configured environment 'windows_test'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for hostname.domain
Info: Applying configuration version '76fb657ed72a947eb8a75faa0f9c2f9a1aea8783'
Notice: /Stage[main]/Profile::Powershell/Psrepository[PowerShell_DEV]/ensure: created (corrective)
Notice: Applied catalog in 5.14 seconds
PS C:\> puppet agent -t
Info: Using configured environment 'windows_test'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for hostname.domain
Info: Applying configuration version '76fb657ed72a947eb8a75faa0f9c2f9a1aea8783'
Error: 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 = 'PowerShell_DEV'
      SourceLocation = 'https://reposerver/nuget/PowerShell_DEV'
      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/windows_test/site/profile/manifests/powershell.pp, line: 14)
Error: 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 = 'PowerShell_DEV'
      SourceLocation = 'https://reposerver/nuget/PowerShell_DEV'
      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/windows_test/site/profile/manifests/powershell.pp, line: 14)
Wrapped exception:
Error when executing command: $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12;     $params = @{
      Name = 'PowerShell_DEV'
      SourceLocation = 'https://reposerver/nuget/PowerShell_DEV'
      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 = []
Error: /Stage[main]/Profile::Powershell/Psrepository[PowerShell_DEV]/ensure: change from 'absent' to 'present' failed: 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 = 'PowerShell_DEV'
      SourceLocation = 'https://reposerver/nuget/PowerShell_DEV'
      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/windows_test/site/profile/manifests/powershell.pp, line: 14) (corrective)
Notice: Applied catalog in 5.02 seconds
PS C:\>

The corrective action can be verified successfully in a new PowerShell-session:

PS C:\> Get-PSRepository
WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
WARNING: Unable to download the list of available providers. Check your internet connection.

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PowerShell_DEV            Trusted              https://hostname.domain/nuget/PowerShell_DEV
PS C:\> Get-PackageProvider nuget

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...

Any help is much appreciated :)

Regards,
Norbert

TLS12 causes systems that are online to go into a corrective change loop

For a subset of our systems we keep getting corrective changes. This is because of the try statement in get-psrepositories. When it fails the rest of the module assumes that the repo isn't installed and tries to install it again.

Following the thread from the hbuckle version this seems to be related to the usage of TLS1.2 now being standard for the CDN's.

Adding: [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 on row 87 of /lib/puppet/provider/psrepository/powershellcore.rb seems to solve it for us.

Support supply credentials for psrepository and package

Hello,

It seems at the moment that it isn't possible to supply credentials while registering the psrepository and/or installing modules using package resource.
I currently cannot use the module due to this. I need to register to an internal nuget repository that requires some credentials.

Thanks in advance for your feedback.

psrepository trusted or untrusted

Im also seeing the psrepository correctivly change the trusted setting each run.

Strangely, ive i run puppet from the cli, it makes no changes. If i run get-psrepository it all looks correct, psgallery is marked as trusted.

Running from the puppet console with debug shows..

stdout = {"name":"PSGallery","source_location":"https://www.powershellgallery.com/api/v2","installation_policy":"untrusted"}

Any ideas why its getting different info back when run via the console?

install_options proxy not working

I'm using the parameter on a node that has nog direct internet access but can use our proxy server

package { 'Posh-ACME':
	ensure          => latest,
	provider        => 'windowspowershell',
	source          => 'PSGallery',
	install_options => [ '-AllowClobber',
			{ '-proxy' => 'http://myproxy.mydomain.be:8080' } ]
}

which returns the error:

Error: Could not prefetch package provider 'windowspowershell': 751: unexpected token at 'WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»'
Error: Failed to apply catalog: 751: unexpected token at 'WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»'

When I install the module by hand:

Install-Module -Proxy "http://myproxy.mydomain.be:8080" -Name Posh-ACME

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install
the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

Everything works well. Upon consecutive Puppet agent run's after the module was installed by hand as in example above:

Error: Could not get latest version: Execution of 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; $mod = Find-Module Posh-ACME; $mod.Version.ToString()' returned 1: WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Posh-ACME'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1397 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
Error: /Stage[main]/Base_software_win::Manage_ps_modules/Package[Posh-ACME]/ensure: change from ['3.17.0'] to 'latest' failed: Could not get latest version: Execution of 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; $mod = Find-Module Posh-ACME; $mod.Version.ToString()' returned 1: WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Posh-ACME'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1397 char:3
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

When using same resource without install_options on a node that has direct internet access, installation works just fine.

Am I missing something here?

Proxy support

If ive got a machine setup with nuget and psgallery configured, i can use pspackage wit the install_options to pass a proxy which works.

However, on a new machine, i dont appear to be able to install nuget or configure the psgallery repo when behind a proxy.

Its possible to pass -Proxy to Install-PackageProvider and Set-PSRepository, but from a quick attept at hacking it into the code it appers the prxy info isnt returned in the get-packageprovider or get-psrepository and as such it changes each subsequent run.

Is it possible to do at east the initial nuget install via a proxy?

Module not found when 'Source' is not specified

When using this in the Puppet file:

pspackageprovider { 'Nuget':
  ensure   => 'present',
  provider => 'windowspowershell',
}

psrepository { 'PSGallery':
  ensure              => present,
  source_location     => 'https://www.powershellgallery.com/api/v2',
  installation_policy => 'trusted',
}

package { 'NexusManagement':
  ensure   => latest,
  provider => 'windowspowershell',
}

I get this error:

Error: Could not get latest version: Execution of 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; $mod = Find-Module NexusManagement -Repository ; $mod.Version.ToString()' returned 1: Find-Module : Missing an argument for parameter 'Repository'. Specify a parameter of type 'System.String[]' and try
again.
At line:1 char:241
+ ... lType]::Tls12; $mod = Find-Module NexusManagement -Repository ; $mod. ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Find-Module], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument,Find-Module
Error: /Stage[main]/Main/Package[NexusManagement]/ensure: change from ['0.2.0'] to 'latest' failed: Could not get latest version: Execution of 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; $mod = Find-Module NexusManagement -Repository ; $mod.Version.ToString()' returned 1: Find-Module : Missing an argument for parameter 'Repository'. Specify a parameter of type 'System.String[]' and try
again.
At line:1 char:241
+ ... lType]::Tls12; $mod = Find-Module NexusManagement -Repository ; $mod. ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Find-Module], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument,Find-Module

The instructions indicate that You do not need to specify the PSGallery with the psrepository type but this doesn't appear to be the case.

If I add 'Source' then it works as it should:

package { 'NexusManagement':
  ensure   => latest,
  source => 'PSGallery',
  provider => 'windowspowershell',
}

I haven't dug into the code but it's clear from the errors that the default source 'PSGallery' is not being passed through.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.