dav*_*vid 3 resources file chef-infra
尝试在本地复制在编译时不存在的文件.例如:
remote_file "/httpfile" do
source "http://wiki.opscode.com/display/chef/Home"
mode "0666"
end
file "/httpfile.bak" do
content IO.read("/httpfile")
only_if {File.exists?("/httpfile")}
end
Run Code Online (Sandbox Code Playgroud)
这个代码将给予ERROR: No such file or directory -该eventough only_if正在使用.这是因为在IO.read文件进入系统之前的编译时发生.(4岁的电子邮件 - http://lists.opscode.com/sympa/arc/chef/2011-08/msg00182.html)
有没有办法强制IO.read("/httpfile")在执行时执行内容?或者现在更好的方法吗?
谢谢
您应该能够使用延迟评估来处理这个问题.我相信语法是这样的:
remote_file "/httpfile" do
source "https://docs.chef.io/"
mode "0666"
end
file "/httpfile.bak" do
lazy { content IO.read("/httpfile") }
only_if {File.exists?("/httpfile")}
end
Run Code Online (Sandbox Code Playgroud)