Reputation: 1614
I'm experiencing an error while trying to create a directory in C:\Program Files using Chef. I am running chef from a powershell environment as Administrator, so there shouldn't be any restrictions as to what actions I can perform.
recipes/default.rb
directory node['app']['unzip_path'] do
action :create
end
attributes/default.rb
default['app']['unzip_path'] = 'C:/Program files/App'
I'm getting this error:
[2013-06-25T01:51:13+00:00] FATAL: Chef::Exceptions::InsufficientPermissions: directory[C:/Program files/App] (app::agent line 15) had an error: Chef::Exceptions::InsufficientPermissions: Cannot create directory[C:/Program files/App] at C:/Program files/App due to insufficient permissions
Additional question: Does chef-solo run as the user running the powershell command or is it running as a special "chef" user
Upvotes: 5
Views: 2210
Reputation: 1
My workaround for this kind of issue with chef not allowing you to make changes inside C:\Program Files\ is to create a simple batch script file like:
@ECHO OFF
MKDIR "C:\\Program Files\\YourDirectory"
:END
And name it programfiles_yourdirectory.bat.erb, then Add it under templates on your cookbook and on the recipe call it like:
template "C:\\chef\\cache\\programfiles_yourdirectory.bat" do
source "programfiles_yourdirectory.bat.erb"
rights :full_control, "Administrators"
end
execute "Create Program Files_YourDirectory Directory" do
cwd "C:\\chef\\cache"
command "programfiles_yourdirectory.bat"
action :run
not_if do ::File.exists?('C:\Program Files\YourDirectory') end
end
This will create a bat template inside chef\cache folder, then chef-client will run the bat file with Admin rights meaning that the folder will be created without prompting for chef insufficient permissions.
Upvotes: 0
Reputation: 2752
Following up on BrianJakovich's answer.
The mkdir_p
call should preserve idempotence in either case, but using a ruby block will probably be better since it will run at the convergence phase:
ruby_block "hack to mkdir on windows" do
block do
FileUtils.mkdir_p node['app']['unzip_path']
end
end
Upvotes: 3
Reputation: 1614
Per http://tickets.opscode.com/browse/CHEF-3787?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel it looks like this is a bug. My resolution to this is to just go the ruby route
require 'fileutils'
FileUtils.mkdir_p node['app']['unzip_path']
The problem here is that I lose the idempotence property that chef's directory resource provides, but if you need to put stuff into program files, this seems to be the only route for now
Upvotes: 1