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


Chronological Thread 
  • From: James Dawson < >
  • To:
  • Subject: [chef] Re: Re: Consuming a resource/provider from within another provider
  • Date: Tue, 17 Apr 2012 03:02:59 +0100

Many thanks for the pointer Andrea, it definitely helped me move forward and understand a bit more - but I'm still not quite there.

The method I included before now looks like this:

def installed?
  poshOutFile = "#{ENV['TEMP']}\\feature_smm_poshoutput.tmp"
  @installed ||= begin
    poshResource = Chef::Resource::Powershell.new("query feature", run_context) do
      code <<-EOH
        Import-Module ServerManager
        $feature = Get-WindowsFeature " "
        Set-Content -Path "#{poshOutFile}" -Value $feature.Installed
      EOH
    end

    poshResource.run_action(:run)

    ( ::File.exist?(poshOutFile) && ::File.read(poshOutFile).include?('True') )
  end
end

The resulting chef-run completes without error and the logging indicates that the resource was executed:

[Tue, 17 Apr 2012 02:15:58 +0100] INFO: Processing windows_feature[AS-NET-Framework] action install (sandbox::poshtest line /chef/cache/cookbooks/sandbox/recipes/poshtest.rb)
DEBUG: C:\Users\ADMINI~1\AppData\Local\Temp\feature_smm_poshoutput.tmp
DEBUG: Checking for 'AS-NET-Framework'
[Tue, 17 Apr 2012 02:15:58 +0100] INFO: Processing powershell[query feature] action run (dynamically defined)
[Tue, 17 Apr 2012 02:15:58 +0100] INFO: powershell[query feature] sh(C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -inputformat none -Command "& { C:\Users\ADMINI~1\AppData\Local\Temp\chef-script20120417-2360-ok3rgn.ps1 }")
[Tue, 17 Apr 2012 02:16:03 +0100] INFO: powershell[query feature] ran successfully
DEBUG: poshOutFile not found
DEBUG: is_installed=false
[Tue, 17 Apr 2012 02:16:03 +0100] INFO: Processing powershell[add feature] action run (dynamically defined)
[Tue, 17 Apr 2012 02:16:03 +0100] INFO: powershell[add feature] sh(C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -inputformat none -Command "& { C:\Users\ADMINI~1\AppData\Local\Temp\chef-script20120417-2360-1o6935p.ps1 }")
[Tue, 17 Apr 2012 02:16:08 +0100] INFO: powershell[add feature] ran successfully
[Tue, 17 Apr 2012 02:16:08 +0100] INFO: windows_feature[AS-NET-Framework] installed feature


...but the 'poshOutFile' is never created suggesting that the Powershell is not actually executed.  As a test I implemented similar logic in a simple recipe calling the powershell resource directly and, as expected, this works fine.

Am I missing anything else that is needed to allow a resource to execute properly when defined dynamically?

Cheers,
James.




Archive powered by MHonArc 2.6.16.

§