我在與廚師一起提供食材。我需要ruby和rubygems作爲root用戶,另一個用戶'deploy'如何在廚師中使用sudo作爲gem命令
ruby和rubygems被安裝並且爲root用戶工作(在測試案例中爲「vagrant」)。
我創建用於一個用戶,以便Capistrano的後部署我的應用程序
user 'deploy' do
password '$1$zOC.txvE$ex544C.YpxV.HqNh/2AKQ0'
home "/home/deploy"
supports :manage_home => true
shell "/bin/bash"
end
然後我試圖改變寶石源,是「部署」用戶
execute 'change sources to our gem server' do
command "gem sources -r http://rubygems.org/ && gem sources -a http://my.gem.server/"
creates "~/.gemrc"
user 'deploy'
cwd "/home/deploy"
end
,但得到這個錯誤
[2014-02-14T14:38:27+00:00] ERROR: execute[change sources to our gem server] (beesor-cookbook::user line 13) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of gem sources -r http://rubygems.org/ && gem sources -a http://my.gem.server/ ----
STDOUT: source http://rubygems.org/ not present in cache
STDERR: ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/vagrant/.gemrc
---- End output of gem sources -r http://rubygems.org/ && gem sources -a http://my.gem.server/ ----
Ran gem sources -r http://rubygems.org/ && gem sources -a http://my.gem.server/ returned 1
的EACCES是/home/vagrant/.gemrc不/home/deploy/.gemrc所以我認爲用戶實際運行到CHEF- 2288(即ENV ['HOME']是錯誤的),但是用模板資源替換執行資源的解決方案無論如何都會正確地減輕它的影響。 – lamont