无法在节点中创建目录

Can't create a directory in node

我在这里写了一个简单的方法,就是在节点中创建一个目录。但是在运行 chef-client 时显示错误。

目录“~/build”做

动作:创建

结束

* Parent directory ~ does not exist, cannot create ~/build
================================================================================
Error executing action `create` on resource 'directory[~/build]'
================================================================================

Chef::Exceptions::EnclosingDirectoryDoesNotExist
------------------------------------------------
Parent directory ~ does not exist, cannot create ~/build

感谢您的宝贵意见。

~$HOME 在 ruby 中没有意义,在 shell 上下文中没问题。

directory "#{ENV['HOME']}/build"会更好

它将在用户 运行 厨师的主目录中创建目录。

如上所述,~ 在 Ruby 中没有上下文,但您可以使用 File.expand_path 将其更改为正确的目录...

directory File.expand_path("~/build") do
  action :create
end

这看起来比上面的方法更清晰,至少对我来说是这样,但它们仍然是正确的。

http://www.ruby-doc.org/core-2.1.2/File.html#method-c-expand_path