2

Vagrant で Chef を使用しており、RVM で Rails スタックを構築したいと考えています。

これまでの Vagrantfile 構成のスニペットは次のとおりです。

...
config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = "cookbooks"

  chef.add_recipe "apt"
  chef.add_recipe "build-essential"
  chef.add_recipe "ntp"
  chef.add_recipe "openssl"
  chef.add_recipe "apache2"
  chef.add_recipe "mysql"
  chef.add_recipe "mysql::server"
  chef.add_recipe "redis"
  chef.add_recipe "git"
  chef.add_recipe "rvm::system"
  chef.add_recipe "rvm::gem_package"
  chef.add_recipe "passenger_apache2"

  chef.json = { 
    :mysql => { 
      :server_root_password => 'root',
      :bind_address => '127.0.0.1'
    },
    :redis => {
      :daemonize => 'yes',
      :port => '6379'
    },
    :rvm => {
      :rubies => 'ruby-1.9.3-p194',
      :global_gems => [
        {:name => 'bundler'},
        {:name => 'rake'},
        {:name => 'passenger',
         :version => '3.0.17'
        }
      ]
    },
    :passenger => {
      :version => '3.0.17'
    }
  }
end

vagrant を起動すると、パッセンジャーをインストールしようとするまでプロビジョニングが機能し、次のエラーが発生します。

...
ERROR: gem_package[passenger] (passenger_apache2::default line 48) has had an error
ERROR: gem_package[passenger] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/passenger_apache2/recipes/default.rb:48:in `from_file') had an error:
gem_package[passenger] (passenger_apache2::default line 48) had an error: NoMethodError: undefined method `join' for nil:NilClass
...

vagrant に sshing すると、RVM と gem が正常にインストールされていることがわかります。

vagrant@lucid32:~$ rvm list

rvm rubies

=* ruby-1.9.3-p194 [ i686 ]

# => - current
# =* - current && default
#  * - default

vagrant@lucid32:~$ gem list

*** LOCAL GEMS ***

bundler (1.2.1)
daemon_controller (1.0.0)
fastthread (1.0.7)
passenger (3.0.17)
rack (1.4.1)
rake (0.9.2.2)
rubygems-bundler (1.1.0)
rvm (1.11.3.5)

手動で実行しても問題なくrvmsudo passenger-install-apache2-module動作します

したがって、rvmをロードせずにシェフがコマンドを実行していることに問題があると確信しています

cookbooks/passenger_apache2/recipes/default.rb のコマンドは次のとおりです: 行 48-55

...
gem_package "passenger" do
  version node[:passenger][:version]
end

execute "passenger_module" do
  command 'passenger-install-apache2-module --auto'
  creates node[:passenger][:module_path]
end

RVM と passaenger_apache に使用しているクックブックは次のとおりです。

私は運が悪いと交換しようとpassenger-install-apache2-module --autoしましたrvmsudo passenger-install-apache2-module --auto...

シェフでrvmとrvmsudoを動作させる方法を知っている人はいますか?

4

1 に答える 1

2

Chefがrvmをロードせずにコマンドを実行していると考えるのは正しいと思います。おそらくrvm_shell、chef-rvmからのコマンドを使用してpassengerをインストールできます。このようなものが機能する可能性があります:

rvm_shell "passenger_module" do
  ruby_string "ruby-1.9.3-p194"
  code        "passenger-install-apache2-module --auto"
  creates node[:passenger][:module_path]
end
于 2012-09-23T11:57:04.087 に答える