LoginSignup
10
2

More than 5 years have passed since last update.

「knife cookbook create」から「chef generate cookbook」へ

Last updated at Posted at 2018-01-05

環境

Mac OS X 10.12.6
$ knife -v
Chef: 13.6.4

よーし、ひさびさにchefでrecipeでも書いてみるかー! :muscle:

https://tsuchikazu.net/chef_solo_start/
を参考にcookbookの雛形を作成して、、と。

$ knife cookbook create unicorn -o site-cookbooks
Error: invalid option: -o
USAGE: Usage: /Users/paranishian/.rbenv/versions/2.4.1/bin/knife (options)
...

あれ、オプションがない... :thinking:

オプションなしで実行。

$ knife cookbook create unicorn
FATAL: knife cookbook create has been removed. Please use `chef generate cookbook` from the ChefDK

おうふ、、、コマンドが変わったっぽい。。
http://d.hatena.ne.jp/rougeref/20170426

ChefDKのインストール

以下からdmgをDLしてpkgインストール。
https://downloads.chef.io/chefdk

$ chef -v
Chef Development Kit Version: 2.4.17
chef-client version: 13.6.4
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.19.2
inspec version: 1.45.13

chefコマンドできた。 :clap:

cookbook作成

cookbook作成のパス指定オプションがないようなので自分で移動して作成。。

$ cd site-cookbooks/
$ chef generate cookbook unicorn
Generating cookbook unicorn
- Ensuring correct cookbook file content
- Ensuring delivery configuration
- Ensuring correct delivery build cookbook content

Your cookbook is ready. Type `cd unicorn` to enter it.

There are several commands you can run to get started locally developing and testing your cookbook.
Type `delivery local --help` to see a full list.

Why not start by writing a test? Tests for the default recipe are stored at:

test/smoke/default/default_test.rb

If you'd prefer to dive right in, the default recipe can be found at:

recipes/default.rb

template作成

$ chef generate template site-cookbooks/unicorn unicorn_app
Recipe: code_generator::template
  * directory[site-cookbooks/unicorn/templates] action create
    - create new directory site-cookbooks/unicorn/templates
  * template[site-cookbooks/unicorn/templates/unicorn_app.erb] action create
    - create new file site-cookbooks/unicorn/templates/unicorn_app.erb
    - update content in file site-cookbooks/unicorn/templates/unicorn_app.erb from none to e3b0c4
    (diff output suppressed by config)

chef卒業してitamaeでも導入していこうかな :sunglasses:

10
2
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
10
2