はじめに
Berksfileでcookbookの取得先を設定する方法について記事を書きます。
Berksfileについては、以下の記事でも紹介しているので併せてご覧下さい。
今回使用するChefのバージョン
バージョン
% knife -v
Chef Infra Client: 17.10.0
%
それぞれの取得先に応じたBerksfileの設定
supermarketから取得したい場合
Berksfile
source 'https://supermarket.chef.io'
cookbook 'td-agent', '~> 3.2.0'
cookbook 'nginx', '~> 12.0.12'
※supermarketは、オープンソースのcookbookの共有を行うサイトになります。
GitHubのリポジトリから取得したい場合
以下のようにcookbookが格納されているGitHubのリポジトリを設定することも可能
Berksfile(リポジトリ指定)
cookbook "apache2", git: "git@github.com:masuwa9028/apache2.git"
Berksfile(ブランチ指定)
cookbook "apache2", git: "git@github.com:masuwa9028/apache2.git" , branch: "update-metadata-rb"
cookbookを取得するコマンド
「はじめに」でご紹介した記事に記載していなかったので、こちらに記載しておきます。
コマンド
berks vendor
実行例
% berks vendor
Top level ::CompositeIO is deprecated, require 'multipart/post' and use `Multipart::Post::CompositeReadIO` instead!
Top level ::Parts is deprecated, require 'multipart/post' and use `Multipart::Post::Parts` instead!
Resolving cookbook dependencies...
Using apache2 (1.0.8) from git@github.com:masuwa9028/apache2.git (at update-metadata-rb)
Using apt (7.4.2)
Using nginx (12.0.12)
Using yum (7.4.0)
Using td-agent (3.2.0)
Vendoring apache2 (1.0.8) to /Users/ma-sato/Code/chef-repo/berks-cookbooks/apache2
Vendoring apt (7.4.2) to /Users/ma-sato/Code/chef-repo/berks-cookbooks/apt
Vendoring nginx (12.0.12) to /Users/ma-sato/Code/chef-repo/berks-cookbooks/nginx
Vendoring td-agent (3.2.0) to /Users/ma-sato/Code/chef-repo/berks-cookbooks/td-agent
Vendoring yum (7.4.0) to /Users/ma-sato/Code/chef-repo/berks-cookbooks/yum
%
以下のようにそれぞれの取得先からcookbookを取得することができていることを確認
ディレクトリ確認
% pwd
/Users/ma-sato/Code/chef-repo : Chef関連のファイルが保管されているプロジェクトのルートディレクトリ
%
% ls -la | grep berks-cookbooks
drwxr-xr-x 7 ma-sato staff 224 7 2 18:14 berks-cookbooks : 取得したcookbookが保管されているディレクトリ
%
berks-cookbooks
の中身に取得したcookbookが保存されていること
取得したcookbook
% cd berks-cookbooks
% ls -la
total 0
drwxr-xr-x 7 ma-sato staff 224 7 2 18:14 .
drwxr-xr-x 15 ma-sato staff 480 7 2 18:14 ..
drwxr-xr-x 10 ma-sato staff 320 7 2 18:14 apache2
drwxr-xr-x 14 ma-sato staff 448 7 2 18:14 apt
drwxr-xr-x 11 ma-sato staff 352 7 2 18:14 nginx
drwxr-xr-x 12 ma-sato staff 384 7 2 18:14 td-agent
drwxr-xr-x 13 ma-sato staff 416 7 2 18:14 yum
%