【问题标题】:Can't find external cookbooks, Vagrant with Chef Solo找不到外部食谱,Vagrant with Chef Solo
【发布时间】:2016-04-02 09:39:27
【问题描述】:

我继承了一个几年未部署的项目。它最初是为使用 Chef 在 Vagrant 机器上进行本地部署而设置的。

当我运行vagrant up 命令时,我收到一个错误,指出它没有找到一些食谱。首先,它没有在Vagrantfile 中指定的cookbooks 目录中找到cookbook。我通过将metadata.rb 文件添加到我试图运行的食谱来解决此问题。好像

#cookbooks/app/metadata.rb
depends "openssl"  # this is in the cookbooks directory
depends "build-essential" # this in the cookbooks directory
depends "git" # this in the cookbooks directory 

现在,当我运行 vagrant up 时,它会中断 git 食谱,因为它找不到它的依赖项之一,dmg(我什至不需要)。

那么我该如何安装这些说明书依赖项以便它能够运行。这些食谱应该安装在我的主机(即托管 Vagrant 盒子的 Mac)上还是安装在 Vagrant 本身上。 我已经下载了 ChefDK 并拥有 Berkshelf,但不确定如何在现有项目中使用它。同样基于solo.rb 文件,它看起来像是在/etc/chef/cookbooks 中寻找食谱。

# solo.rb
log_level :info
cookbook_path "/etc/chef/cookbooks"
json_attribs "/etc/chef/cookbooks/node_staging.json"
role_path "/etc/chef/roles"

这是运行 vagrant up 的示例输出。

==> default: Running chef-solo...
==> default: stdin: is not a tty
==> default: [2015-11-30T19:46:31+00:00] INFO: Forking chef instance to converge...
==> default: [2015-11-30T19:46:31+00:00] WARN:
==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
==> default: SSL validation of HTTPS requests is disabled. HTTPS connections are still
==> default: encrypted, but chef is not able to detect forged replies or man in the middle
==> default: attacks.
==> default:
==> default: To fix this issue add an entry like this to your configuration file:
==> default:
==> default: ```
==> default:   # Verify all HTTPS connections (recommended)
==> default:   ssl_verify_mode :verify_peer
==> default:
==> default:   # OR, Verify only connections to chef-server
==> default:   verify_api_cert true
==> default: ```
==> default:
==> default: To check your SSL configuration, or troubleshoot errors, you can use the
==> default: `knife ssl check` command like so:
==> default:
==> default: ```
==> default:   knife ssl check -c /tmp/vagrant-chef/solo.rb
==> default: ```
==> default:
==> default: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
==> default: Starting Chef Client, version 11.18.12
==> default: [2015-11-30T19:46:31+00:00] INFO: *** Chef 11.18.12 ***
==> default: [2015-11-30T19:46:31+00:00] INFO: Chef-client pid: 1844
==> default: [2015-11-30T19:46:32+00:00] INFO: Setting the run_list to ["role[vagrant]"] from CLI options
==> default: [2015-11-30T19:46:32+00:00] INFO: Run List is [role[vagrant]]
==> default: [2015-11-30T19:46:32+00:00] INFO: Run List expands to [app::default]
==> default: [2015-11-30T19:46:32+00:00] INFO: Starting Chef Run for geosurvey
==> default: [2015-11-30T19:46:32+00:00] INFO: Running start handlers
==> default: [2015-11-30T19:46:32+00:00] INFO: Start handlers complete.
==> default: Compiling Cookbooks...
==> default:
==> default: Running handlers:
==> default: [2015-11-30T19:46:32+00:00] ERROR: Running exception handlers
==> default: Running handlers complete
==> default:
==> default: [2015-11-30T19:46:32+00:00] ERROR: Exception handlers complete
==> default: [2015-11-30T19:46:32+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: Chef Client failed. 0 resources updated in 1.06392657 seconds
==> default: [2015-11-30T19:46:32+00:00] ERROR: Cookbook dmg not found. If you're loading dmg from another cookbook, make sure you configure the dependency in your metadata
==> default: [2015-11-30T19:46:32+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

【问题讨论】:

  • 如果没有什么是私有的,最好能共享整个项目,有很多配置方法,一种是安装本地说明书,另一种是让 shell 脚本在 VM 上安装它们等很难说它是如何做到的几年前不看它

标签: vagrant chef-infra chef-solo


【解决方案1】:

Vagrant 本身不支持 Berkshelf 集成。有一个可用的插件 (vagrant-berkshelf) 可以引入依赖项并将它们同步到 VM,但不建议这样做,因为它可能有点不稳定。测试厨房(使用kitchen-vagrant)通常更容易。您也可以使用berks vendor 命令手动下载deps 并将它们转储到chef-solo 可以使用的文件夹结构中。

【讨论】:

    【解决方案2】:

    我有类似的问题,并设法解决了这些问题。 安装 vagrant berkshelf 插件解决了它的问题。据我了解,必须阅读每本食谱并输入 barks install appart 来配置 vagrant barkshelf,如下所示:

    config.berkshelf.enabled = true
    config.berkshelf.berksfile_path = "./cookbooks/database/Berksfile"
    

    但我正在探索这个运行不佳的供应商解决方案。 据我了解,如果我有一个名为“./cookbooks-source”的目录并且里面有一堆食谱(cb1,cb2,cb3,...),我将不得不迭代它们中的每一个并输入类似

    berks vendor ../../cookbooks
    

    但是这些食谱依赖中的每一个都可能相互冲突?另外我觉得很不方便。也在探索 berks 包,但不知道如何将它连接到 vagrant。

    【讨论】: