【发布时间】:2015-05-19 18:24:57
【问题描述】:
我有以下问题,我认为是因为我不了解 Chef LWRP 中的变量范围。
您可以查看 https://github.com/jkleinlercher/chef_problems 的食谱并简单地测试一下厨房的行为。
尽管我定义了以下非常相似的资源,但我认识到,“颜色”属性继承自之前定义的资源。属性“颜色”默认为“['蓝色']”,并且在提供程序中,元素“洋红色”被添加到数组中。但是,第二个和第三个资源从前一个资源继承了整个数组。这对我来说很奇怪......
recipes/default.rb 中的资源定义:
chef_problems_problem1 "test1" do
address "myaddress1"
action :install
end
chef_problems_problem1 "test2" do
address "myaddress2"
action :install
end
chef_problems_problem1 "test3" do
address "myaddress3"
action :install
end
在厨房收敛的输出中,您会看到变量 new_resource.colors 继承了先前资源的值:
* chef_problems_problem1[test1] action install
new_resource.colors at the beginning: ["blue"]
Values of local variables:
address: myaddress1
colors: ["blue"]
adding magenta to local variable colors
colors after adding magenta: ["blue", "magenta"]
new_resource.colors at the end: ["blue", "magenta"]
* chef_problems_problem1[test2] action install
new_resource.colors at the beginning: ["blue", "magenta"]
Values of local variables:
address: myaddress2
colors: ["blue", "magenta"]
adding magenta to local variable colors
colors after adding magenta: ["blue", "magenta", "magenta"]
new_resource.colors at the end: ["blue", "magenta", "magenta"]
* chef_problems_problem1[test3] action install
new_resource.colors at the beginning: ["blue", "magenta", "magenta"]
Values of local variables:
address: myaddress3
colors: ["blue", "magenta", "magenta"]
adding magenta to local variable colors
colors after adding magenta: ["blue", "magenta", "magenta", "magenta"]
new_resource.colors at the end: ["blue", "magenta", "magenta", "magenta"]
也许你能帮我找出问题出在哪里。
【问题讨论】:
标签: ruby chef-infra lwrp