0

Hopefully this is the right place for this. i am using Puppet on Windows Server and looking to install a Powershell module found in the Powershell Gallery using Puppet. I have read through https://forge.puppet.com/puppetlabs/dsc/readme however there is nothing about ensuring a gallery module is installed on the system. I am assuming it would be through something like

dsc_module { 'module_name':
  dsc_ensure => 'present',
}

This didn't seem to work though. No error either. My guess is that I will need to use somethingn like chocolatey. can anyone confirm if this is possible?

Laywah
  • 99
  • 7

1 Answers1

1

You can do this with a different module:

The powershellmodule Puppet module looks like it can manage Package repositories and install modules from them, though I've not used it myself. Example from the module's description page:

pspackageprovider {'Nuget':
  ensure => 'present'
}

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

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

I did have a look and I couldn't see an in-box way to install a PowerShell module using just DSC; there's not a DSC resource called 'module' which is what I think you were trying to configure using the Puppet DSC module.

EDIT:

Just checked again and there is a resource for package management. So you could update your original code as follows:

dsc_packagemanagement { 'module_name':
  dsc_ensure => 'present',
  dsc_name => 'module_name',
}

https://docs.microsoft.com/en-us/powershell/dsc/packagemanagementdscresource

john
  • 1,995
  • 2
  • 17
  • 30
  • Sorry for the delay on getting back to your response. I haven't been able to get either methods to work. both give an error around unknown resource type. it doesn't like `dsc_packagemanagement` or `dsc_PackageManagement`. I also got the error in the first bit with `pspackageprovider` – Laywah Aug 07 '18 at 05:40
  • after looking into this further. Your first answer has worked. I had to import an extra module which I found out that I didn't have. The only thing I have adjusted however was `installation_policy => 'untrusted',`. I have tested this and it still seems to work fine. I just feel a little better from a security point of view not trusting the repo. – Laywah Aug 07 '18 at 08:10
  • Although there is an MS DSC "PackageManagement" resource and Puppet Labs have "converted" almost all MS resources, for some reason, they haven't included this one (yet), so dsc_packagemanagement {...} won't work. The "converted" list of "resources" to "types" can be found: https://github.com/puppetlabs/puppetlabs-dsc/tree/master/lib/puppet/type – woter324 May 30 '19 at 20:14
  • The [hbuckle module](https://forge.puppet.com/hbuckle/powershellmodule) hasn't been updated in 2 years and doesn't work because of the shift sites not supporting TLS <1.2 and Windows Powershell's lack of support for TLS 1.2 out of the box. There is a forked version from [encore](https://forge.puppet.com/encore/powershellmodule) that includes the TLS fix. – logicaldiagram Jul 10 '20 at 20:16