diff --git a/README.md b/README.md index a4e24f8..33886a2 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,19 @@ file{"C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Micr `puppet-powershellmodule` implements a [package type](http://docs.puppet.com/references/latest/type.html#package) with a resource provider, which is built into Puppet. +The implementation supports the [install_options](https://puppet.com/docs/puppet/6.2/type.html#package-attribute-install_options) attribute which can be used to pass additional options to the PowerShell Install-Modules command, e.g.: + +``` +package { 'xPSDesiredStateConfiguration': + ensure => latest, + provider => 'windowspowershell', + source => 'PSGallery', + install_options => [ '-AllowClobber', + { '-proxy' => 'http://proxy.local.domain' } ] +} + +``` + ### pspackageprovider #### Properties/Parameters diff --git a/lib/puppet/provider/package/powershellcore.rb b/lib/puppet/provider/package/powershellcore.rb index ca8f4bd..e9bf471 100644 --- a/lib/puppet/provider/package/powershellcore.rb +++ b/lib/puppet/provider/package/powershellcore.rb @@ -55,10 +55,10 @@ def update # @param options [Array] # @return Concatenated list of options # @api private - def install_options - return unless @resource[:install_options] + def install_options(options) + return unless options - @resource[:install_options].collect do |val| + options.collect do |val| case val when Hash val.keys.sort.collect do |k| @@ -88,7 +88,7 @@ def install_command command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force" command << " -RequiredVersion #{@resource[:ensure]}" unless [:present, :latest].include? @resource[:ensure] command << " -Repository #{@resource[:source]}" if @resource[:source] - command << " #{install_options}" if @resource[:install_options] + command << " #{install_options(@resource[:install_options])}" if @resource[:install_options] command end @@ -103,7 +103,7 @@ def latest_command def update_command command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force" command << " -Repository #{@resource[:source]}" if @resource[:source] - command << " #{install_options}" if @resource[:install_options] + command << " #{install_options(@resource[:install_options])}" if @resource[:install_options] command end end