有没有什么办法来延迟资源的属性分辨率,直到"执行"相? [英] Is there any way to delay a resource's attribute resolution until the "execute" phase?
问题描述
我有两个LWRPs。与创建一个磁盘卷,格式化和安装它在虚拟机上的第一个交易,我们会打电话给这个资源 cloud_volume
。第二个资源(不是真正重要的它做什么)需要一个UUID为新格式化的卷这是一个必需的属性,我们会打电话给这个资源 foobar的
。
I have two LWRPs. The first deals with creating a disk volume, formatting it, and mounting it on a virtual machine, we'll call this resource cloud_volume
. The second resource (not really important what it does) needs a UUID for the newly formatted volume which is a required attribute, we'll call this resource foobar
.
资源 cloud_volume
和 foobar的
在配方像下面这样被使用。
The resources cloud_volume
and foobar
are used in a recipe something like the following.
volumes.each do |mount_point, volume|
cloud_volume "#{mount_point}" do
size volume['size']
label volume['label']
action [:create, :initialize]
end
foobar "#{mount_point}" do
disk_uuid node[:volumes][mount_point][:uuid] # This is set by cloud_volume
action [:do_stuff]
end
end
所以,当我做了厨师来看,我收到了必需的参数disk_identifier丢失!
例外。
在做一些挖我发现食谱分两期进行处理,编译阶段和执行阶段后。它看起来像这个问题是在编译的时候,因为这是在时间节点,点[:卷] [装入点] [:UUID]
未设置。
After doing some digging I discovered that recipes are processed in two phases, a compile phase and an execute phase. It looks like the issue is at compile time as that is the point in time that node[:volumes][mount_point][:uuid]
is not set.
不幸的是我不能使用OPS code的<一个诀窍href=\"http://web.archive.org/web/20120226074250/http://wiki.ops$c$c.com/display/chef/Evaluate+and+Run+Resources+at+Compile+Time\"相对=nofollow>此处作为cloud_volume LWRP正在使用的通知(所以它会落入文件中所示的反模式)
Unfortunately I can't use the trick that OpsCode has here as notifications are being used in the cloud_volume LWRP (so it would fall into the anti-pattern shown in the documentation)
所以,这一切后,我的问题是,有没有什么办法让周围的 disk_uuid
的值在编译时已知的要求?
So, after all this, my question is, is there any way to get around the requirement that the value of disk_uuid
be known at compile time?
推荐答案
一个更清洁的方式是使用的 lazy属性评估。这将评估节点[:卷] [装入点] [:UUID]
在执行期间,而不是编译
A cleaner way would be to use Lazy Attribute Evaluation. This will evaluate node[:volumes][mount_point][:uuid]
during execution time instead of compile
foobar "#{mount_point}" do
disk_uuid lazy { node[:volumes][mount_point][:uuid] }
action [:do_stuff]
end
这篇关于有没有什么办法来延迟资源的属性分辨率,直到&QUOT;执行&QUOT;相?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!