LoginSignup
19
18

More than 5 years have passed since last update.

Windows でも Berkshelf を

Posted at

Berkshelf が便利そうなので使おうとしたんだけど、やっぱりというか Windows では茨の道だったのでメモしておく。

試した環境は以下の通り。

  • Windows 8.1 x64
  • Chef 11.12.4
  • Berkshelf 3.1.3

とりあえず Chef は Chocolatey でインストールしておきましょう。

cinst chef-client

Chef リポジトリは C:\Chef に配置することにします。

続けて Berkshelf は Chef に同梱されている gem でインストールします。

where gem
// C:\opscode\chef\embedded\bin\gem
// C:\opscode\chef\embedded\bin\gem.bat
gem install berkshelf

インストールはとにかく時間がかかります。暴走したかと思うくらいかかるので気長に待ちましょう。
(MacBook Air 2012 Middle で30分くらい?)
現時点では Windows + Berkshelf の組み合わせは問題があり、失敗例がいくつか見つかります。
3.x 系のインストールに時間がかかるのでキャンセルして、 2.X 系のインストールも試したりしたところ、こちらは失敗しました。その後気長に待ったところ 3.x のインストールが成功しました。

Berkfile は次のように書きます。

Berkfile
source "https://api.berkshelf.com"

cookbook 'windows'
cookbook 'chef_handler'
cookbook 'powershell'

2.x 系の情報だと Berkfile 先頭は site :opscode と書きますが、 3.x 系は上記のように書きます。これで berks vendor cookbooks とすると cookbook がダウンロードされます。

と言いたいところですが、失敗します。

Resolving cookbook dependencies...
Fetching cookbook index from https://api.berkshelf.com...
C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect': SSL_connec
t returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify f
ailed (Faraday::SSLError)
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:800:in `block i
n connect'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/timeout.rb:100:in `timeout'

        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:800:in `connect
'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:756:in `do_star
t'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:745:in `start'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:1285:in `reques
t'
        from C:/opscode/chef/embedded/lib/ruby/1.9.1/net/http.rb:1027:in `get'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/adapter/net_http.rb:78:in `perform_request'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/adapter/net_http.rb:39:in `call'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/request/retry.rb:87:in `call'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/response.rb:8:in `call'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/response.rb:8:in `call'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/rack_builder.rb:139:in `build_response'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/connection.rb:377:in `run_request'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/faraday-0.9.0/lib
/faraday/connection.rb:140:in `get'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/berkshelf-api-cli
ent-1.2.0/lib/berkshelf/api_client/connection.rb:62:in `universe'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/berkshelf-3.1.3/l
ib/berkshelf/source.rb:22:in `build_universe'
        from C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/berkshelf-3.1.3/l
ib/berkshelf/installer.rb:21:in `block (2 levels) in build_universe'

SSL verify cannot be turned off · Issue #1 · berkshelf/berkshelf-api-client にある通り、SSL証明書を指定するとダウンロードできるようになります。

まずは http://curl.haxx.se/ca/cacert.pem をダウンロードします。
それを C:\Chef など適当な個所に配置し、 Ruby から見えるようにしてあげます。

SET SSL_CERT_FILE=C:\Chef\cacert.pem

これで cookbook がダウンロードできるようになりました。

19
18
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
19
18