[chef] Consuming a resource/provider from within another provider


Chronological Thread 
  • From: James Dawson < >
  • To:
  • Subject: [chef] Consuming a resource/provider from within another provider
  • Date: Thu, 12 Apr 2012 00:49:26 +0100

Hi,

I'm trying to extend the 'Feature' resource in the Windows cookbook to also support using the Powershell module that is available in Windows 2008 R2.

I was intending on using the Powershell resource/provider to actually execute the necessary commands, but am struggling to get this working - I've tried various combinations without much success but am new to Ruby so feel like I'm stumbling in the dark really.

Here is how I'm trying to use it in my implementation of the 'installed?' method:

def installed?
  poshOutFile = Tempfile.new('feature_smm')
  @installed ||= begin
    Chef::Resource::Powershell.new("query feature") do
      code <<-EOH
        import-module ServerManager
        $feature = Get-WindowsFeature " "
        Set-Content -Path "#{poshOutFile.path}"  -Value $feature.Installed
      EOH
    end

    !(poshOutFile.nil?) && ((poshOutFile.read).casecmp 'true')
  end
end

This particular attempt doesn't throw any errors but nothing actually happens, presumably because I'm only only instantiating the resource and not actually executing it. Other attempts typically resulted in 'method_missing' or 'undefined method' exceptions.

As a side question, I didn't see any way to pass information back from the invoked Powershell command (standard out doesn't seem to be accessible in the same way as with the 'shell_out' provider - or have I missed something here too?) so have resorted to using a file to store the result - is this the best approach?

Thanks in advance for any help.

Cheers,
James.




Archive powered by MHonArc 2.6.16.

§