How I can capture values in command line and add to recipe?

前端 未结 3 1296
渐次进展
渐次进展 2020-12-06 08:09

I am new to Chef and Ruby

I need to pass two variables to Chef on the command line and have those variables available in a recipe.

How I can capture these va

3条回答
  •  天命终不由人
    2020-12-06 08:47

    You can set variables inside recipes by calling commands

    nodename = `cat /etc/chef/client.rb | grep "node_name" | sed -e 's/\//g' | sed '/^$/d;s/[[:blank:]]//g' | sed 's/\"//g'`
    

    And then use the variable for other chef blocks

    execute "echo nodename for node #{nodename}"
     command "echo #{nodename}"
     action :run
     only_if {nodename == "node1"}
    end
    

    This will get the node.name attribute from the client.rb file without asking for it to the chef server.

提交回复
热议问题