如何运行厨师菜谱?

如何运行厨师菜谱?

可以通过从 galaxy 或 puppetforge 下载角色并在无主模式下运行来使用 Ansible 和 Puppet 安装软件。

目的

目的是安装MongoDB使用 chef masterless。我只想下载一本食谱并运行它。

试图

  • 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)

第二次尝试

可以使用以下方式运行 Chef 代码这个例子由@TimHaintz 提供:

[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

问题

  1. 何时使用knife、、或?chef-applychef-clientchef-shellchef-solo
  2. 从市场运行食谱的最短路径是什么?

答案1

knife cookbook site download只会为您提供原始 tarball,而不是可直接与 Chef 一起使用的格式。如果您正在寻找功能齐全的 chef-solo 工作流程,我会将该knife-solo插件与 Berkshelf 一起使用。

将想要使用的菜谱放入Berksfile,然后使用knife solo cook将它们传输到目标节点并运行chef-solo

答案2

@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

以下片段基于这个答案

配置.rb

cookbook_path [
  '/home/user/berks-cookbooks'
]

配置.json

{
  "run_list": [
    "terraform"
  ]
}

跑步

sudo chef-solo -c config.rb -j config.json

相关内容