1
0

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のrecipe内でgemを追加してロードする

Posted at

#目的
Chefのrecipe内でgemを追加してロードする方法を紹介します。
ここでは、recipeのリソース"ruby_block"で'deep_merge'をロードする例を紹介します。
一応、インターネット接続がないChef clientでも動くように考慮します。

#構成
OSはRHEL7.3,ChefはServer Client方式。
利用したChef Clientは13.4.24-1.el7, Chef Serverは12.16.14-1.el7

#手順
deep_merge-1.2.1.gemをダウンロードして、cookbookのfiles/default以下に配置しておきます。

以下recipeのサンプルです。

cookbook_file "/tmp/deep_merge-1.2.1.gem" do
  source "deep_merge-1.2.1.gem"
end

execute "deep_merge install" do
  command "/opt/chef/embedded/bin/gem install --local /tmp/deep_merge-1.2.1.gem"
  notifies :run, "ruby_block[sample ruby block]"
end

ruby_block 'sample ruby block' do
  block do
    require 'json'
    $LOAD_PATH << '/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/deep_merge-1.2.1/lib'
    require 'deep_merge'

    ~~deep_mergeを利用した処理~~

  end
  action :nothing
end

以上

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?