puppetlabs / puppetlabs-dsc_lite

DSC to Puppet runtime integration and module generation tasks
Apache License 2.0
8 stars 26 forks source link

Cannot install package with PackageManagement. #25

Closed BarnumD closed 6 years ago

BarnumD commented 6 years ago

Given the following code, puppet errors with the error directly below.

 dsc {'Install_Docker':
    dsc_resource_name        => 'PackageManagement',
    dsc_resource_module_name => 'PackageManagement',
    dsc_resource_properties  => {
      ensure => 'present',
      name   => 'docker ',
      source => 'DockerMsftProvider',
    }
  }
Error: PowerShell DSC resource MSFT_PackageManagement  failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find package so
urce 'DockerMsftProvider'. Use Get-PackageSource to see all available package sources.
Error: /Stage[main]/Profiles::foo/Dsc[Install_Docker]/ensure: change from 'absent' to 'present' failed: PowerShell DSC resource MSFT_PackageManagement  failed to execute Set-TargetResource functionality with error message: The running command stopped because the
preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find package source 'DockerMsftProvider'. Use Get-PackageSource to see all available package sources.

If I change source to ProviderName I get the following error:

Error: PowerShell DSC resource MSFT_PackageManagement  failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No match was found for th
e specified search criteria and package name 'docker '. Try Get-PackageSource to see all available registered package sources.
Error: /Stage[main]/Profiles::foo/Dsc[Install_Docker]/ensure: change from 'absent' to 'present' failed: PowerShell DSC resource MSFT_PackageManagement  failed to execute Set-TargetResource functionality with error message: The running command stopped because the
preference variable "ErrorActionPreference" or common parameter is set to Stop: No match was found for the specified search criteria and package name 'docker '. Try Get-PackageSource to see all available registered package sources.

My best guess is that this is because the provider is installed:

Get-PackageProvider -Listavailable
Name                     Version          DynamicOptions
----                     -------          --------------
DockerMsftProvider       1.0.0.1          Update
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
nuget                    2.8.5.208
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

But it is not 'imported':

get-dscprovider
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

Note, that I had installed the DockerMsftProvider with the following code:

  dsc {'PS_Module_DockerMsftProvider':
    dsc_resource_name        => 'PackageManagement',
    dsc_resource_module_name => 'PackageManagement',
    dsc_resource_properties  => {
      ensure => 'present',
      name   => 'DockerMsftProvider',
      source => 'PSGallery',
    }
  }

How can I get it to use the installed packageprovider that's not imported into puppets current session? If I were in powershell, I think the answer would be Import-PackageProvider -Name "DockerMsftProvider" but I'm trying to make this work without exec statements.

Iristyle commented 6 years ago

Thanks for the report @BarnumD. If the PackageManagementSource DSC resource is not finding the actual package provider, that seems like a bug in the DSC resource implementation.

Do you have a working DSC manifest that performs the same task? The docs for that resource are available at https://docs.microsoft.com/en-us/powershell/dsc/packagemanagementdscresource