1

私が持っているもの:シェフ;

必要なもの:RVMがインストールされていnode[:deploy][:user][:name]ます。システム全体ではなく、ユーザー全体のインストールが必要です。

私が最近試したこと:

script 'install_rvm' do
  user = node[:deploy][:user][:name]
  interpreter '/bin/bash'
  code "su -l #{user} -c '\curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable'"
  not_if { ::File.exists? "/home/#{user}/.rvm" }
end

su -l <username> -c '\curl <long_url> | bash -s stable'テストサーバーで手動で実行すると、確実に完全に機能します。Chefが同じコードを実行することを期待しており、ログでは実行しているように見えexecuteますが、実際には存在しないため、次のリソースは失敗します/home/<username>/.rvmuser node[:deploy][:user][:name]はい、Chefではユーザーを変更する代わりにユーザーを指定できることを知っていますsuが、何らかの理由でそれを実行rvmすると、自分自身をインストールしようとし/root/.rvmます(envが正しくリセットされませんか?)。さて、私は質問したいのですが、なぜシェフはそのような非常に単純なタスクでも非常にくだらないのですか?しかし、私は間違った場所を選んだようです、それで問題は私が間違っているのか、それとも明らかな何かを見逃しているのですか?

4

2 に答える 2

1

Fletcher Nicholのchef-rvmを使用してみませんか?これは、 ChefでRVMを処理するためにサポートされている方法です。

于 2013-02-02T21:49:27.340 に答える
0

まあ、少なくともそれはうまくいき、Chefでそれを行うためのすべてのより良い方法があなたのために失敗した場合に役立つかもしれません。これがrubyをインストールするためのリソースです

execute 'install_rvm' do
  user('root')
  user = node[:deploy][:user][:name]
  command "su -l #{user} -c '\curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable'"
  not_if { ::File.exists? "/home/#{user}/.rvm" }
end

そして、gemsetそれがまだ存在しない場合に作成するボーナス1:

execute 'rvm_install_ruby' do
  user('root')
  user = node[:deploy][:user][:name]
  ruby = node[:deploy][:ruby]
  gemset = node[:deploy][:gemset]
  command "su -l #{user} -c 'rvm use #{ruby}@#{gemset} --install --create'"
  not_if do
    if latest_patchlevel = `rvm list`.scan(/(ruby-#{ruby}-p)(\d+)/).map{ |a| a.last.to_i }.sort.last
      `rvm list gemsets`.match /ruby-#{ruby}-p#{latest_patchlevel}@#{gemset}/
    end
  end
end
于 2013-02-01T12:46:33.120 に答える