LoginSignup
6
6

More than 5 years have passed since last update.

chefのmetadata.rbをchef以外から利用する

Last updated at Posted at 2014-03-20

chefのmetadata.rbには、そのcookbookに関する様々な情報を書いておくことができます。

実際community cookbookのcookbookを見てみると、metadata.rbに色々書いてあるのもあります。
例: https://github.com/opscode-cookbooks/mysql/blob/master/metadata.rb

この情報を使うと色々な便利なことができるような気がします。
chefと外部システムの連携、自動テストとか、cookbook viewerとかeditorとか?
以下の方法でchefの外からこのファイルを読み込めます。

require 'chef/cookbook/metadata'

metadata = Chef::Cookbook::Metadata.new
metadata.from_file('./metadata.rb')

で読み込めます。
pry上ですが、上で紹介したmysql cookbookのmetadata.rbに対して実際にやってみると、

$ pry -rchef/cookbook/metadata
[1] pry(main)> metadata = Chef::Cookbook::Metadata.new
=> #<Chef::Cookbook::Metadata:0x007fd6830505f8
 @attributes={},
 @conflicting={},
 @cookbook=nil,
 @dependencies={},
 @description="A fabulous new cookbook",
 @groupings={},
 @license="none",
 @long_description="",
 @maintainer="YOUR_COMPANY_NAME",
 @maintainer_email="YOUR_EMAIL",
 @name="",
 @platforms={},
 @providing={},
 @recipes={},
 @recommendations={},
 @replacing={},
 @suggestions={},
 @version=0.0.0>

[2] pry(main)> metadata.from_file('./metadata.rb')
=> {"display_name"=>"Ruby Executable Directory which should gain MySQL support",
 "default"=>"system ruby",
 "choice"=>[],
 "calculated"=>false,
 "type"=>"string",
 "required"=>"optional",
 "recipes"=>[]}
[3] pry(main)> metadata
=> #<Chef::Cookbook::Metadata:0x007fd6830505f8
 @attributes=
  {"mysql/server_root_password"=>
    {"display_name"=>"MySQL Server Root Password",
     "description"=>"Randomly generated password for the mysqld root user",
     "default"=>"randomly generated",
     "choice"=>[],
     "calculated"=>false,
     "type"=>"string",
     "required"=>"optional",
     "recipes"=>[]},
   "mysql/bind_address"=>
    {"display_name"=>"MySQL Bind Address",
     "description"=>"Address that mysqld should listen on",
     "default"=>"ipaddress",
     "choice"=>[],
     "calculated"=>false,
     "type"=>"string",
     "required"=>"optional",
     "recipes"=>[]},
   "mysql/data_dir"=>
    {"display_name"=>"MySQL Data Directory",
     "description"=>"Location of mysql databases",
     "default"=>"/var/lib/mysql",
     "choice"=>[],
     "calculated"=>false,
     "type"=>"string",
     "required"=>"optional",
     "recipes"=>[]}
(中略)
},
 @conflicting={},
 @cookbook=nil,
 @dependencies=
  {"openssl"=>"~> 1.1",
   "build-essential"=>"~> 1.4",
   "homebrew"=>">= 0.0.0",
   "windows"=>">= 0.0.0"},
 @description="Installs and configures mysql for client or server",
 @groupings={},
 @license="Apache 2.0",
 @long_description=
  "setup Cookbook\n==============\nTODO: Enter the cookbook description here.\n\ne.g.\nThis cookbook makes your favorite breakfast sandwhich.\n\nRequirements\n------------\nTODO: List your cookbook requirements. Be sure to include
 @maintainer="Opscode, Inc.",
 @maintainer_email="cookbooks@opscode.com",
 @name="mysql",
 @platforms=
  {"redhat"=>">= 0.0.0",
   "amazon"=>">= 0.0.0",
   "centos"=>">= 0.0.0",
   "debian"=>">= 0.0.0",
   "ubuntu"=>">= 0.0.0",
   "freebsd"=>">= 0.0.0",
   "mac_os_x"=>">= 0.0.0",
   "scientific"=>">= 0.0.0",
   "suse"=>">= 0.0.0",
   "windows"=>">= 0.0.0"},
 @providing={},
 @recipes=
  {"mysql"=>"Includes the client recipe to configure a client",
   "mysql::client"=>
    "Installs packages required for mysql clients using run_action magic",
   "mysql::server"=>
    "Installs packages required for mysql servers w/o manual intervention",
   "mysql::server_ec2"=>"Performs EC2-specific mountpoint manipulation"},
 @recommendations={},
 @replacing={},
 @suggestions={},
 @version=4.1.1>
[4] pry(main)>
6
6
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
6
6