2016-07-22 83 views
0

我正面臨一個奇怪的問題。當廚師從用戶數據(cloud-init)執行時,我的下面的廚師食譜失敗。composer.phar安裝問題(cloudinit vs manual)

它要求輸入HOME/COMPOSER_HOME env變量。

但是,如果我從SSH終端運行手動廚師客戶端(或者甚至直接在終端上運行命令),它運行良好。

PS:composer.phar和composer.json由開發商提供的(在WordPress拉鍊捆綁)

==配方片段==

# Install Composer 

script "install_composer" do 
    interpreter "bash" 
    user "root" 
    cwd "#{node.apache.default_docroot}/html" 
    code <<-EOH 
    /opt/rh/rh-php56/root/usr/bin/php composer.phar install 
    EOH 
    not_if {File.exists?("#{node.default_docroot}/html/composer.lock")} 
end 

==當從SSH終端運行==

* script[install_composer] action run 
    - execute "bash" "/tmp/chef-script20160722-5397-1sjwxg9" 

==雲INIT-SNI Output.log PPET ==

================================================================================ 
Error executing action `run` on resource 'script[install_composer]' 
================================================================================ 

Mixlib::ShellOut::ShellCommandFailed 
------------------------------------ 
Expected process to exit with [0], but received '1' 
---- Begin output of "bash" "/tmp/chef-script20160722-2013-r6sdpo" ---- 
STDOUT: 
STDERR: [RuntimeException]                   
    The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly 
---- End output of "bash" "/tmp/chef-script20160722-2013-r6sdpo" ---- 
Ran "bash" "/tmp/chef-script20160722-2013-r6sdpo" returned 1 

Resource Declaration: 
--------------------- 
# In /var/chef/cache/cookbooks/webps-commportal/recipes/wordpress.rb 

49: script "install_composer" do 
50: interpreter "bash" 
51: user "root" 
52: cwd "#{node.apache.default_docroot}/html" 
53: code <<-EOH 
54: /opt/rh/rh-php56/root/usr/bin/php composer.phar install 
55: EOH 
56: not_if {File.exists?("#{node.apache.default_docroot}/html/composer.lock")} 
57: end 
58: 

Compiled Resource: 
------------------ 
# Declared in /var/chef/cache/cookbooks/webps-commportal/recipes/wordpress.rb:49:in `from_file' 

script("install_composer") do 
    action "run" 
    retries 0 
    retry_delay 2 
    guard_interpreter :default 
    command "\"bash\" \"/tmp/chef-script20160722-2013-r6sdpo\"" 
    backup 5 
    cwd "/opt/rh/httpd24/root/var/www/html" 
    returns 0 
    user "root" 
    code "\t/opt/rh/rh-php56/root/usr/bin/php composer.phar install\n" 
    interpreter "bash" 
    cookbook_name "webps-commportal" 
    recipe_name "wordpress" 
    not_if { #code block } 
end 

---- Begin output of "bash" "/tmp/chef-script20160722-2013-r6sdpo" ---- 
STDOUT: 
STDERR: [RuntimeException]                   
    The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly 
---- End output of "bash" "/tmp/chef-script20160722-2013-r6sdpo" ---- 
Ran "bash" "/tmp/chef-script20160722-2013-r6sdpo" returned 1 

回答

1

添加environment HOME: '/root'script資源(或類似)。這是必要的,因爲廚師不會爲你設置這個變量。當你通過SSH登錄時,它會被你的登錄shell設置,然後繼承到chef-client進程。

+0

讓我試試。我會回來的結果。謝謝 – charsidrogo

+0

Woot這工作! '[2016-07-22T06:14:58-04:00] INFO:處理腳本[install_composer]操作運行(webps-commportal :: WordPress的線49) [2016-07-22T06:15:25 -04:00] INFO:腳本[install_composer]跑successfully' ==更新廚師資源塊== '腳本 「install_composer」 做 \t解釋 「慶典」 \t用戶 「根」 \t環境「HOME '=>「/ root」 \t cwd「#{node.apache.default_docroot}/html」 \t代碼<< - EOH \t的/ opt/RH/RH-php56 /根的/ usr/bin中/ PHP composer.phar安裝--no正在進行 \t EOH \t not_if {File.exists?(「#{} node.apache.default_docroot/HTML /composer.lock「)} end' – charsidrogo

+0

評論不保存格式,但很高興它工作:) – coderanger