Reputation: 537
I have write the simple recipe here which is to create a directory in the node. But it shows error while running the chef-client.
directory "~/build" do
action :create
end
* 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
thanks for your valuable comments.
Upvotes: 1
Views: 2565
Reputation: 15784
~
or $HOME
have no meaning in ruby, they're ok in shell context.
directory "#{ENV['HOME']}/build"
would be better.
it will create the directory in the home dir of the user running chef.
Upvotes: 1
Reputation: 997
As mentioned above, ~ has no context in Ruby, but you can use File.expand_path to alter it to the correct directory...
directory File.expand_path("~/build") do
action :create
end
This looks cleaner than the approach above, at least to me, but they are still correct.
http://www.ruby-doc.org/core-2.1.2/File.html#method-c-expand_path
Upvotes: 2