[chef] Re: Re: Re: Re: RE: Order of Execution of resources in a cookbook


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: RE: Order of Execution of resources in a cookbook
  • Date: Mon, 10 Feb 2014 12:28:26 -0800


On Monday, February 10, 2014 at 12:19 PM, wrote:


Your issue is that you are running some commands during the recipe compile phase, whereas resources are added to a queue called the resource collection and then evaluated after all compilation is completed (the “converge phase”). You can find some more documentation about this process here: http://docs.opscode.com/essentials_nodes_chef_run.html

 
cmd = powershell_out(script)
#Chef::Log.info("-------------KKS-------------")
#Chef::Log.info(cmd)
#Chef::Log.info(cmd.stdout)
#Chef::Log.info(cmd.stderr)

x = cmd.stdout.chop
#puts "Value of x : " + x

powershell_script "Install_IIS" do
code <<-EOH
$processLog = 'C:\\Temp\\Chef_PS_Log.txt'
function Date { Get-Date -Format 'yyyy/dd/MM HH:mm:ss' }
Add-Content $processLog (($date=Date) + ' ' + '----- 1-1 Inside
Install_IIS ----')
Add-Content $processLog (($date=Date) + ' ' + 'IIS Server role is not
installed ')
#Install-WindowsFeature -name "Web-Server" -IncludeManagementTools
-IncludeAllSubFeature -WhatIf
Install-WindowsFeature -name "Web-Server" -IncludeManagementTools
-IncludeAllSubFeature
EOH
only_if { x == '1' }
end
I can see here that your goal is to conditionally run this `powershell_script` resource based on the result of your `powershell_out` command. We’re going to add better support for powershell in these not_if/only_if guards in the future, but for now, your best bet is to move evaluation of your powershell script inside the code block you give to `only_if`. Something like

powershell_script “something” do
  # other stuff
  only_if do
    cmd = powershell_out($powershell_code)
    cmd.stdout.chomp == expected_result
  end
end

HTH,

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§