2014-02-14 1 views
0

나는 요리사에게 제공하는 것을 삼가하고 있습니다. root 사용자와 다른 사용자의 'deploy'에 대해 루비와 루비 젬이 필요합니다.요리사의 보석 명령에 sudo를 사용하는 방법

루비와 루비 젬이 설치되어 있고 루트 사용자 (테스트 케이스 "방랑제")에서 작동합니다.

나는

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 

답변

2

이것은 execute 리소스를 사용할 때의 문제입니다. 권한이없는 사용자로 실행 리소스를 실행하고 있습니다. 그러나 비공유 사용자가 관련 파일을 계속 소유하게 하시겠습니까? Stephen이 제안한 코드는 작동하지만 .gemrc은 루트 사용자가 소유하게됩니다. Rubygems가 gemrcs를 읽는 방법에 따라, 파일이 다른 사용자에 의해 소유되는 것이 마음에 들지 않을 수 있습니다. 따라서 수동으로 chownchmod 명령을 사용하거나 execute 명령을 사용하거나 템플릿 만 사용해야합니다. 당신이 당신의 컴퓨터에 로컬로 명령을 실행하면

, 당신은 볼 수 생성 된 gemrc은 다음과 같습니다 다음

template '/home/deploy/.gemrc' do 
    source 'gemrc.erb' 
    user 'deploy' 
    group 'deploy' 
    mode '0644' 
    variables(source: 'http://my.gem.server') 
end 

과 :

--- 
:sources: 
- http://my.gem.server 

내가 대신 순수 template 자원을 사용하는 것이 좋습니다 관련 erb :

--- 
:sources: 
- <%= @source %> 

여러 개의 소스 엔드 포인트를 지원합니다. 당신이 나무 등의 자원을 사용하고 있기 때문에 또한 :

  • 당신은 요리사 클라이언트 실행에 좋은은 diff 출력을 얻을

    당신은 매우 유용 출력에 자식 스타일은 diff를 볼 수 있습니다 템플릿 소스 (예를 들어) 변경을 한 후 보석을 설치해야하는 경우

  • 디버깅을 위해 당신은 변화

    의 다른 자원을 알릴 수 안전하게이 알림을 사용할 수 있습니다. 이러한 통지는 템플릿이 변경 될 때 트리거 :

EACCES이 /home/vagrant/.gemrc에
template '/home/deploy/.gemrc' do 
    # ... 
    notifies :install, 'gem_package[foo]', :immediately 
end 

gem_package 'foo' do 
    action :nothing 
end 
+0

나는 사용자가 실제로 CHEF-으로 실행되는 생각 때문에 /home/deploy/.gemrc하지 2288 (예 : ENV [ 'HOME']이 잘못되었습니다.)하지만 실행 리소스를 템플릿 리소스로 바꾸는 솔루션으로 문제가 해결됩니다. – lamont

관련 문제