You can't update an attribute from inside a powershell_script that is executing. You could do something like the below (with one example where the PowerShell script evaluates to $true and one where it evals to $false:node.default['test'] = falseruby_block 'Terminate Chef Client Run' doaction :nothingblock doChef::Application.fatal! 'The attribute was true!'endonly_if {node['test'] == true}endruby_block 'Fail PowerShell Test' doblock donode.default['test'] = trueendguard_interpreter :powershell_scriptonly_if "test-path c:/windows2"notifies :run, 'ruby_block[Terminate Chef Client Run]', :immediatelyendruby_block 'Pass PowerShell Test' doblock donode.default['test'] = trueendguard_interpreter :powershell_scriptonly_if "test-path c:/windows"notifies :run, 'ruby_block[Terminate Chef Client Run]', :immediatelyendSteven MurawskiCommunity Software Development Engineer @ ChefMicrosoft MVP - PowerShell
http://stevenmurawski.comOn 7/10/2015 9:07:23 AM, Pradeep Kumar < " target="_blank"> > wrote:
Hi All,i have a boolean attribute. i want to set the attribute to true conditionally inside a powershell_script.if the attribute is true i would like to throw a fatal error message and abort chef run.i'm stuck on how to set the attribute value from inside the powershell.in the below case #{node.default['saas_wfa_prod_db_server']['fail_chef']=true} is running irrespective of the if condition. (may be its evaluated during compile)below is the code. can some one please help.--code--node.default['saas_wfa_prod_db_server']['fail_chef'] = falsepowershell_script "get available offline disks" docode <<-EOH$sysstoragelength =4$drivestoragelength=5if($sysstoragelength -lt $drivestoragelength){#{node.default['saas_wfa_prod_db_server']['fail_chef']=true}}EOHendif (node['saas_wfa_prod_db_server']['fail_chef'])Chef::Application.fatal!("sufficient number of disks not available in offline state", 42)end--pradeep
Archive powered by MHonArc 2.6.16.