How to pass value from one resource to another resource in chef recipe?

前端 未结 2 1303
独厮守ぢ
独厮守ぢ 2021-01-21 01:15

I am trying to change an attribute in one resource and want to use updated value in another resource but updated value is not getting reflected in another resources. please help

2条回答
  •  春和景丽
    2021-01-21 01:52

    Lazy is good, but here is another approach. You may use node.run_state for your purposes.

    Here is usage example from https://docs.chef.io/recipes.html

    package 'httpd' do
      action :install
    end
    
    ruby_block 'randomly_choose_language' do
      block do
        if Random.rand > 0.5
          node.run_state['scripting_language'] = 'php'
        else
          node.run_state['scripting_language'] = 'perl'
        end
      end
    end
    
    package 'scripting_language' do
      package_name lazy { node.run_state['scripting_language'] }
      action :install
    end
    

提交回复
热议问题