4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

chefでchef-rvmを利用してみる

Last updated at Posted at 2013-06-17

chefでrvm環境を取り扱いたかったのでchef-rvmを利用してみる。
ついでにberkshelfでcookbookを管理してみる。

あまり他のレシピを利用するとかしたことなかったので勉強になったがこんなんで良いのかな?

環境

  • Amazon Linux:2012.09
  • rvmをシステム(/usr/local/rvm以下)にインストール済
  • chefを以下の方法でインストール済
$ curl -L https://www.opscode.com/chef/install.sh | sudo bash
  • berkshelf:2.0.3インストール済

chefでchef-rvmを利用してみる

  • ベース作成
$ mkdir hoge
$ cd hoge
$ berks init
  • berkshelfでchef-rvm導入
 $ echo "cookbook 'chef-rvm', git: 'https://github.com/fnichol/chef-rvm.git'" >> Berksfile
 $ berks install --path cookbooks
  • chef-rvmを利用するcookbook作成
  • リソースの書き方がgithubにあるReadmeと違って苦労した
 $ cd cookbooks
 $ berks cookbook hoge

 $ vi hoge/recipes/default.rb 
 $ cat vi hoge/recipes/default.rb 
include_recipe "chef-rvm"

chef_rvm_ruby "jruby" do
  action :install
end

 $ echo "depends          'chef-rvm'" >> hoge/metadata.rb

 $ cd ..
  • chef-soloでの実行準備
 $ mkdir .chef

 $ vi .chef/solo.rb
 $ cat .chef/solo.rb
file_cache_path "/tmp/chef-solo"
cookbook_path "/home/ec2-user/hoge/cookbooks"

 $ vi .chef/chef.json 
 $ cat .chef/chef.json
{
  "run_list": [ "recipe[hoge]" ]
}
  • chef-soloで実行
  • => rvmでjrubyがインストールされる
 $ sudo chef-solo -c .chef/solo.rb -j .chef/chef.json
Starting Chef Client, version 11.4.4
Compiling Cookbooks...
Recipe: chef-rvm::default
  * chef_gem[rvm] action install (up to date)
/home/ec2-user/chef-repo/cookbooks/chef-rvm/libraries/rvm_chef_user_environment.rb:49: warning: class variable access from toplevel
Converging 2 resources
  * chef_gem[rvm] action install (up to date)
Recipe: hoge::default
  * chef-rvm_ruby[jruby] action install/home/ec2-user/chef-repo/cookbooks/chef-rvm/libraries/rvm_chef_user_environment.rb:32: warning: class variable access from toplevel
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?