Chef
如何執行廚師食譜?
可以使用 Ansible 和 Puppet 安裝軟體,方法是從galaxy 或 puppetforge 下載角色並無主執行。
目標
目的是使用 chef masterless安裝MongoDB 。我只想下載一本食譜並執行它。
試圖
knife cookbook site download mongodb3
將食譜保存在/home/user/mongodb3-5.3.0.tar.gz
- 焦油被提取
- 基於此文件,我嘗試使用 執行食譜
chef-client --local -o recipe['mongodb3']
,但結果是:[2016-11-18T10:35:28+01:00] WARN: No config file found or specified on command line, using command line options. [2016-11-18T10:35:28+01:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. Starting Chef Client, version 12.15.19 [2016-11-18T10:36:05+01:00] WARN: Run List override has been provided. [2016-11-18T10:36:05+01:00] WARN: Original Run List: [] [2016-11-18T10:36:05+01:00] WARN: Overridden Run List: [recipe[mongodb3]] resolving cookbooks for run list: ["mongodb3"] ================================================================================ Error Resolving Cookbooks for Run List: ================================================================================ Missing Cookbooks: ------------------ No such cookbook: mongodb3 Expanded Run List: ------------------ * mongodb3 Platform: --------- x86_64-linux Running handlers: [2016-11-18T10:36:05+01:00] ERROR: Running exception handlers Running handlers complete [2016-11-18T10:36:05+01:00] ERROR: Exception handlers complete Chef Client failed. 0 resources updated in 36 seconds [2016-11-18T10:36:05+01:00] FATAL: Stacktrace dumped to /home/user/.chef/local-mode-cache/cache/chef-stacktrace.out [2016-11-18T10:36:05+01:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report [2016-11-18T10:36:05+01:00] ERROR: 412 "Precondition Failed" [2016-11-18T10:36:05+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
嘗試 2
可以使用@TimHaintz 提供的範例執行 Chef 程式碼:
[2016-11-28T08:19:12+01:00] WARN: No config file found or specified on command line, using command line options. Starting Chef Client, version 12.15.19 [2016-11-28T08:19:15+01:00] WARN: Run List override has been provided. [2016-11-28T08:19:15+01:00] WARN: Original Run List: [] [2016-11-28T08:19:15+01:00] WARN: Overridden Run List: [recipe[helloworld]] resolving cookbooks for run list: ["helloworld"] Synchronizing Cookbooks: - helloworld (0.0.0) Installing Cookbook Gems: Compiling Cookbooks... Converging 1 resources Recipe: helloworld::default * file[/home/user/x.txt] action create - create new file /home/user/x.txt - update content in file /home/user/x.txt from none to 787ec7 --- /home/user/x.txt 2016-11-28 08:19:15.527057085 +0100 +++ /home/user/.chef-x20161128-7678-no5ia3.txt 2016-11-28 08:19:15.527057085 +0100 @@ -1 +1,2 @@ +HELLO WORLD - restore selinux security context [2016-11-28T08:19:15+01:00] WARN: Skipping final node save because override_runlist was given Running handlers: Running handlers complete Chef Client finished, 1/1 resources updated in 03 seconds
問題
- 何時使用
knife
,chef-apply
,chef-client
,chef-shell
或chef-solo
?- 從市場上執行食譜的最短方法是什麼?
knife cookbook site download
只是給你一個原始的壓縮包,而不是你可以直接與 Chef 一起使用的格式。如果您正在尋找功能齊全的 Chef-solo 工作流程,我會將該knife-solo
外掛與 Berkshelf 一起使用。將要使用的說明書放入
Berksfile
,然後使用knife solo cook
將它們傳送到目標節點並執行chef-solo
。
@coderanger 建議使用 berkshelf並且在本文件中找到了以下片段:
伯克斯文件
source "https://supermarket.chef.io" cookbook "terraform"
安裝說明書
user@host ~ $ berks install Resolving cookbook dependencies... Fetching cookbook index from https://supermarket.chef.io... Installing ark (1.1.0) Installing compat_resource (12.16.2) Installing seven_zip (2.0.2) Installing build-essential (7.0.2) Installing ohai (4.2.2) Using terraform (0.5.3) Installing mingw (1.2.4) Installing windows (2.1.1)
user@host ~ $ berks vendor Resolving cookbook dependencies... Using terraform (0.5.3) Using ark (1.1.0) Using mingw (1.2.4) Using ohai (4.2.2) Using build-essential (7.0.2) Using seven_zip (2.0.2) Using compat_resource (12.16.2) Using windows (2.1.1) Vendoring ark (1.1.0) to /home/user/berks-cookbooks/ark Vendoring build-essential (7.0.2) to /home/user/berks-cookbooks/build-essential Vendoring compat_resource (12.16.2) to /home/user/berks-cookbooks/compat_resource Vendoring mingw (1.2.4) to /home/user/berks-cookbooks/mingw Vendoring ohai (4.2.2) to /home/user/berks-cookbooks/ohai Vendoring seven_zip (2.0.2) to /home/user/berks-cookbooks/seven_zip Vendoring terraform (0.5.3) to /home/user/berks-cookbooks/terraform Vendoring windows (2.1.1) to /home/user/berks-cookbooks/windows
以下片段基於此答案:
配置文件
cookbook_path [ '/home/user/berks-cookbooks' ]
配置文件
{ "run_list": [ "terraform" ] }
跑
sudo chef-solo -c config.rb -j config.json