开始学习cookbook了(http://docs.opscode.com/essentials_cookbook_directory.html)
官方文档介绍了3个命令,本以为很容易,没想到费了一番周折:
1. 最最简单的就是创建一个cookbook了,执行: D:\Tools\Chef\chef-repo-master>knife cookbook create cb_first,就会生成文件夹:D:\Tools\Chef\chef-repo-master\cookbooks\cb_first,里面有cookbook默认的文件。
2. 接着试了一下下载一个官方的cookbook,执行:D:\Tools\Chef\chef-repo-master>knife cookbook site download java,就会下载一个tar.gz文件。
3. 最后尝试安装一个cookbook的时候发生问题,执行:D:\Tools\Chef\chef-repo-master>knife cookbook site install java,首先碰到的问题是,我的repo没有加入到git,这是因为我是直接把git上的源代码打包下载下来的,所以好解决,把他假如到我的git repo里面就OK了。接着再次执行,发现还是报错:ERROR: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0]。看了真是一头雾水,网上查了点资料,发现可以使用-VV开关输出详细信息:knife cookbook site install java -VV,终于明白了是git.exe找不到,因为不在PATH环境变量中。通过everything定位git.exe,这东西还真奇怪,路径是:C:\Users\PunCha\AppData\Local\GitHub\PortableGit_93e8418133eb85e81a81e5e19c272776524496c6\bin\git.exe。。。晕。。git这东西还真没搞明白怎么用。那就把路径加到环境变量去吧,第三次运行,终于OK了,输出如下:
D:\Tools\Chef\chef-repo-master>knife cookbook site install java Installing java to D:/Tools/Chef/chef-repo-master/cookbooks Checking out the master branch. Creating pristine copy branch chef-vendor-java Downloading java from the cookbooks site at version 1.10.0 to D:/Tools/Chef/chef -repo-master/cookbooks/java.tar.gz Cookbook saved: D:/Tools/Chef/chef-repo-master/cookbooks/java.tar.gz Removing pre-existing version. Uncompressing java version 1.10.0. removing downloaded tarball 1 files updated, committing changes Creating tag cookbook-site-imported-java-1.10.0 Checking out the master branch. Updating b6c4159..191847e Fast-forward cookbooks/java/.gitignore | 7 + cookbooks/java/CHANGELOG.md | 92 +++++++ cookbooks/java/CONTRIBUTING.md | 257 ++++++++++++++++++++ cookbooks/java/Gemfile | 3 + cookbooks/java/LICENSE | 201 ++++++++++++++++ cookbooks/java/README.md | 213 +++++++++++++++++ cookbooks/java/attributes/default.rb | 77 ++++++ .../files/default/tests/minitest/openjdk_test.rb | 25 ++ .../files/default/tests/minitest/oracle_test.rb | 24 ++ cookbooks/java/metadata.json | 45 ++++ cookbooks/java/metadata.rb | 19 ++ cookbooks/java/providers/ark.rb | 264 +++++++++++++++++++++ cookbooks/java/recipes/default.rb | 33 +++ cookbooks/java/recipes/openjdk.rb | 97 ++++++++ cookbooks/java/recipes/oracle.rb | 68 ++++++ cookbooks/java/recipes/oracle_i386.rb | 52 ++++ cookbooks/java/recipes/windows.rb | 28 +++ cookbooks/java/resources/ark.rb | 38 +++ cookbooks/java/templates/default/oracle.jinfo.erb | 6 + 19 files changed, 1549 insertions(+) create mode 100644 cookbooks/java/.gitignore create mode 100644 cookbooks/java/CHANGELOG.md create mode 100644 cookbooks/java/CONTRIBUTING.md create mode 100644 cookbooks/java/Gemfile create mode 100644 cookbooks/java/LICENSE create mode 100644 cookbooks/java/README.md create mode 100644 cookbooks/java/attributes/default.rb create mode 100644 cookbooks/java/files/default/tests/minitest/openjdk_test.rb create mode 100644 cookbooks/java/files/default/tests/minitest/oracle_test.rb create mode 100644 cookbooks/java/metadata.json create mode 100644 cookbooks/java/metadata.rb create mode 100644 cookbooks/java/providers/ark.rb create mode 100644 cookbooks/java/recipes/default.rb create mode 100644 cookbooks/java/recipes/openjdk.rb create mode 100644 cookbooks/java/recipes/oracle.rb create mode 100644 cookbooks/java/recipes/oracle_i386.rb create mode 100644 cookbooks/java/recipes/windows.rb create mode 100644 cookbooks/java/resources/ark.rb create mode 100644 cookbooks/java/templates/default/oracle.jinfo.erb Cookbook java version 1.10.0 successfully installed Installing windows to D:/Tools/Chef/chef-repo-master/cookbooks Checking out the master branch. Creating pristine copy branch chef-vendor-windows Downloading windows from the cookbooks site at version 1.8.4 to D:/Tools/Chef/ch ef-repo-master/cookbooks/windows.tar.gz Cookbook saved: D:/Tools/Chef/chef-repo-master/cookbooks/windows.tar.gz Removing pre-existing version. Uncompressing windows version 1.8.4. removing downloaded tarball 1 files updated, committing changes Creating tag cookbook-site-imported-windows-1.8.4 Checking out the master branch. Updating 191847e..f0b683b Fast-forward cookbooks/windows/CHANGELOG.md | 161 ++++++ cookbooks/windows/CONTRIBUTING | 29 + cookbooks/windows/LICENSE | 201 +++++++ cookbooks/windows/README.md | 609 +++++++++++++++++++++ cookbooks/windows/attributes/default.rb | 22 + .../default/handlers/windows_reboot_handler.rb | 76 +++ cookbooks/windows/libraries/feature_base.rb | 41 ++ cookbooks/windows/libraries/helper.rb | 86 +++ cookbooks/windows/libraries/registry_helper.rb | 357 ++++++++++++ cookbooks/windows/libraries/version.rb | 204 +++++++ cookbooks/windows/libraries/windows_privileged.rb | 94 ++++ cookbooks/windows/metadata.json | 31 ++ cookbooks/windows/metadata.rb | 9 + cookbooks/windows/providers/auto_run.rb | 32 ++ cookbooks/windows/providers/batch.rb | 62 +++ cookbooks/windows/providers/feature_dism.rb | 47 ++ .../windows/providers/feature_servermanagercmd.rb | 47 ++ cookbooks/windows/providers/package.rb | 251 +++++++++ cookbooks/windows/providers/pagefile.rb | 153 ++++++ cookbooks/windows/providers/path.rb | 35 ++ cookbooks/windows/providers/printer.rb | 100 ++++ cookbooks/windows/providers/printer_port.rb | 102 ++++ cookbooks/windows/providers/reboot.rb | 31 ++ cookbooks/windows/providers/registry.rb | 72 +++ cookbooks/windows/providers/shortcut.rb | 56 ++ cookbooks/windows/providers/task.rb | 124 +++++ cookbooks/windows/providers/zipfile.rb | 91 +++ cookbooks/windows/recipes/default.rb | 34 ++ cookbooks/windows/recipes/reboot_handler.rb | 32 ++ cookbooks/windows/resources/auto_run.rb | 30 + cookbooks/windows/resources/batch.rb | 36 ++ cookbooks/windows/resources/feature.rb | 40 ++ cookbooks/windows/resources/package.rb | 46 ++ cookbooks/windows/resources/pagefile.rb | 29 + cookbooks/windows/resources/path.rb | 28 + cookbooks/windows/resources/printer.rb | 41 ++ cookbooks/windows/resources/printer_port.rb | 40 ++ cookbooks/windows/resources/reboot.rb | 29 + cookbooks/windows/resources/registry.rb | 33 ++ cookbooks/windows/resources/shortcut.rb | 35 ++ cookbooks/windows/resources/task.rb | 46 ++ cookbooks/windows/resources/zipfile.rb | 33 ++ 42 files changed, 3655 insertions(+) create mode 100644 cookbooks/windows/CHANGELOG.md create mode 100644 cookbooks/windows/CONTRIBUTING create mode 100644 cookbooks/windows/LICENSE create mode 100644 cookbooks/windows/README.md create mode 100644 cookbooks/windows/attributes/default.rb create mode 100644 cookbooks/windows/files/default/handlers/windows_reboot_hand ler.rb create mode 100644 cookbooks/windows/libraries/feature_base.rb create mode 100644 cookbooks/windows/libraries/helper.rb create mode 100644 cookbooks/windows/libraries/registry_helper.rb create mode 100644 cookbooks/windows/libraries/version.rb create mode 100644 cookbooks/windows/libraries/windows_privileged.rb create mode 100644 cookbooks/windows/metadata.json create mode 100644 cookbooks/windows/metadata.rb create mode 100644 cookbooks/windows/providers/auto_run.rb create mode 100644 cookbooks/windows/providers/batch.rb create mode 100644 cookbooks/windows/providers/feature_dism.rb create mode 100644 cookbooks/windows/providers/feature_servermanagercmd.rb create mode 100644 cookbooks/windows/providers/package.rb create mode 100644 cookbooks/windows/providers/pagefile.rb create mode 100644 cookbooks/windows/providers/path.rb create mode 100644 cookbooks/windows/providers/printer.rb create mode 100644 cookbooks/windows/providers/printer_port.rb create mode 100644 cookbooks/windows/providers/reboot.rb create mode 100644 cookbooks/windows/providers/registry.rb create mode 100644 cookbooks/windows/providers/shortcut.rb create mode 100644 cookbooks/windows/providers/task.rb create mode 100644 cookbooks/windows/providers/zipfile.rb create mode 100644 cookbooks/windows/recipes/default.rb create mode 100644 cookbooks/windows/recipes/reboot_handler.rb create mode 100644 cookbooks/windows/resources/auto_run.rb create mode 100644 cookbooks/windows/resources/batch.rb create mode 100644 cookbooks/windows/resources/feature.rb create mode 100644 cookbooks/windows/resources/package.rb create mode 100644 cookbooks/windows/resources/pagefile.rb create mode 100644 cookbooks/windows/resources/path.rb create mode 100644 cookbooks/windows/resources/printer.rb create mode 100644 cookbooks/windows/resources/printer_port.rb create mode 100644 cookbooks/windows/resources/reboot.rb create mode 100644 cookbooks/windows/resources/registry.rb create mode 100644 cookbooks/windows/resources/shortcut.rb create mode 100644 cookbooks/windows/resources/task.rb create mode 100644 cookbooks/windows/resources/zipfile.rb Cookbook windows version 1.8.4 successfully installed Installing chef_handler to D:/Tools/Chef/chef-repo-master/cookbooks Checking out the master branch. Creating pristine copy branch chef-vendor-chef_handler Downloading chef_handler from the cookbooks site at version 1.1.4 to D:/Tools/Ch ef/chef-repo-master/cookbooks/chef_handler.tar.gz Cookbook saved: D:/Tools/Chef/chef-repo-master/cookbooks/chef_handler.tar.gz Removing pre-existing version. Uncompressing chef_handler version 1.1.4. removing downloaded tarball 1 files updated, committing changes Creating tag cookbook-site-imported-chef_handler-1.1.4 Checking out the master branch. Updating f0b683b..73dbb64 Fast-forward cookbooks/chef_handler/CHANGELOG.md | 28 +++ cookbooks/chef_handler/CONTRIBUTING | 29 +++ cookbooks/chef_handler/LICENSE | 201 +++++++++++++++++++++ cookbooks/chef_handler/README.md | 103 +++++++++++ cookbooks/chef_handler/attributes/default.rb | 30 +++ .../chef_handler/files/default/handlers/README | 1 + cookbooks/chef_handler/metadata.json | 29 +++ cookbooks/chef_handler/metadata.rb | 7 + cookbooks/chef_handler/providers/default.rb | 93 ++++++++++ cookbooks/chef_handler/recipes/default.rb | 33 ++++ cookbooks/chef_handler/recipes/json_file.rb | 28 +++ cookbooks/chef_handler/resources/default.rb | 34 ++++ 12 files changed, 616 insertions(+) create mode 100644 cookbooks/chef_handler/CHANGELOG.md create mode 100644 cookbooks/chef_handler/CONTRIBUTING create mode 100644 cookbooks/chef_handler/LICENSE create mode 100644 cookbooks/chef_handler/README.md create mode 100644 cookbooks/chef_handler/attributes/default.rb create mode 100644 cookbooks/chef_handler/files/default/handlers/README create mode 100644 cookbooks/chef_handler/metadata.json create mode 100644 cookbooks/chef_handler/metadata.rb create mode 100644 cookbooks/chef_handler/providers/default.rb create mode 100644 cookbooks/chef_handler/recipes/default.rb create mode 100644 cookbooks/chef_handler/recipes/json_file.rb create mode 100644 cookbooks/chef_handler/resources/default.rb Cookbook chef_handler version 1.1.4 successfully installed D:\Tools\Chef\chef-repo-master>
看了下Git,提交了3个chang list:
1. Import java version 1.10.0
2. Import windows version 1.8.4
3. Import chef_handler version 1.1.4
然后在D:\Tools\Chef\chef-repo-master\cookbooks下面又多了3个cookbook,分别和上面对应:java, windows, chef_handler。
目前为止,感觉我还在chef的门口游荡。。。还没入门。。。这东西学习门槛还真高!一般学习门槛高的都活不长,看看Chef能走多远咯~今天到此为止,休息休息一会儿。。看越狱去,嘎嘎