Vagrant up 厨师供应在正常情况下失败

Vagrant up chef provision fails on normal up

所以我以为我已经完成了所有工作,但似乎我仍然遗漏了一些东西。

当我vagrant destroy --force && vagrant up时,一切正常。它按预期创建盒子和厨师配置工作。

但是,如果我执行 vagrant halt,然后执行 vagrant up,我会收到以下错误:

==> default: [2015-01-26T14:04:21+00:00] ERROR: Cookbook install not found. If you're loading install from another cookbook, make sure you configure the dependency in your metadata
==> default: [2015-01-26T14:04:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

install 是一个自定义配方,它基本上只是安装了一堆包,没什么特别的。

这里是default.rb,它位于site_cookbooks/install/recipies/

# Install repos for PHP 5.5
remote_file "Creating PHP5.5 Repo" do
    path                    "#{Chef::Config[:file_cache_path]}/webtatic_repo_latest.rpm"
    source                  "http://mirror.webtatic.com/yum/el6/latest.rpm"
    action                  :create
end

rpm_package "Installing PHP5.5 Repo" do
    package_name            "jmxtrans"
    source                  "#{Chef::Config[:file_cache_path]}/webtatic_repo_latest.rpm"
    action                  :install
end

# Install PHP 5.5 packages
yum_package "Installing PHP5.5" do
    package_name            "php55w"
    version                 "5.5.20-1.w6"
    allow_downgrade         true    
end

# Install PHP 5.5 Cli
yum_package "Installing PHP5.5-cli" do
    package_name            "php55w-cli"
    version                 "5.5.20-1.w6"
    allow_downgrade         true
end

# Install PHP 5.5 common
yum_package "Installing PHP5.5-common" do
    package_name            "php55w-common"
    version                 "5.5.20-1.w6"
    allow_downgrade         true
end

# Install PHP 5.5 mysql
yum_package "Installing PHP5.5-mysql" do
    package_name            "php55w-mysql"
    version                 "5.5.20-1.w6"
    allow_downgrade         true
end

# Install the mysql server
mysql_service "default" do
    instance                "property.ca"
    version                 "5.5"
    initial_root_password   node["install"]["mysql"]["password"]
    port                    "3306"
    bind_address            "0.0.0.0"
    action                  [:create, :start]
end

# Install the mysql client
mysql_client "default" do
    version                 "5.5"
    action                  :create
end

# Install Apache 2.4 repo
remote_file "Installing Apache 2.4 repo" do
    path                    "/etc/yum.repos.d/epel-httpd24.repo"
    source                  "http://repos.fedorapeople.org/repos/jkaluza/httpd24/epel-httpd24.repo"
    action                  :create
end

# Install Apache 2.4 package
yum_package "Installing Apache 2.4" do
    package_name            "httpd24-apr"
    version                 "1.4.8-2.el6"
    allow_downgrade         true
end

# Install Git package
yum_package "Installing Git" do
    package_name            "git"
    version                 "1.7.1-3.el6_4.1"
    allow_downgrade         true
end


# Download composer
remote_file "Downloading composer" do
    path "#{Chef::Config[:file_cache_path]}/composer_installer"
    source "https://getcomposer.org/installer"
    action :create
end

# Install composer
bash "Install composer" do
    user                    "root"
    cwd                     "/usr/bin"
    code <<-EOH
    php #{Chef::Config[:file_cache_path]}/composer_installer -- ----install-/usr/local/bin --filename=composer
    EOH
end

我有一个 metadata.rb,它位于 site_cookbooks/install,看起来像这样:

name 'install'
maintainer 'SynackSA'
maintainer_email 'synacksa@email.ca'
license 'MIT'
description 'Install the dev environment'
version '1.0.0'

depends 'mysql'

我的Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
    config.vm.box = "chef/centos-6.5"

    # Plugins
    config.berkshelf.enabled = true
    config.omnibus.chef_version = :latest    

    config.vm.hostname = "site.ca"    
    config.vm.network "public_network"

    config.vm.synced_folder "/Users/PropertyDev/Projects/property.ca", "/var/www/site.ca"
    config.vm.synced_folder "/Users/MyUser/Projects/scripts", "/var/www/scripts"


    # run: "always"
    config.vm.provision "chef_solo" do |chef|

        chef.json = {
            "install" => {
                "mysql" => {
                    "password" => "password"
                }
            }
        }

        chef.cookbooks_path = "site_cookbooks"
        chef.add_recipe "install"
        # chef.log_level = :debug
    end

end

我的Berksfile:

# encoding: utf-8
source 'https://supermarket.chef.io'

cookbook "mysql", "~> 6.0.10"
cookbook "install", path: "site_cookbooks/install"

来自 vagrant reload --provisiondebug_level = :debug

的完整调试输出
» vagrant reload --provision
==> default: Loading Berkshelf datafile...
==> default: Sharing cookbooks with VM
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Updating Vagrant's Berkshelf...
==> default: Resolving cookbook dependencies...
==> default: Fetching 'install' from source at site_cookbooks/install
==> default: Using install (1.0.0) from source at site_cookbooks/install
==> default: Using rbac (1.0.2)
==> default: Using smf (2.2.1)
==> default: Using yum-mysql-community (0.1.12)
==> default: Using resource-control (0.1.1)
==> default: Using yum (3.5.2)
==> default: Using mysql (6.0.10)
==> default: Vendoring install (1.0.0) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/install
==> default: Vendoring mysql (6.0.10) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/mysql
==> default: Vendoring rbac (1.0.2) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/rbac
==> default: Vendoring resource-control (0.1.1) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/resource-control
==> default: Vendoring smf (2.2.1) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/smf
==> default: Vendoring yum (3.5.2) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/yum
==> default: Vendoring yum-mysql-community (0.1.12) to /Users/User/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150127-46811-19w58cq-default/yum-mysql-community
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) en4: Display Ethernet
2) en0: Wi-Fi (AirPort)
3) en1: Thunderbolt 1
4) en2: Thunderbolt 2
5) p2p0
6) awdl0
7) bridge0
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
    default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Checking for host entries
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/User/Projects/vagrant_test
    default: /var/www/scripts => /Users/User/Projects/scripts
    default: /var/www/site.ca => /Users/User/Projects/site.ca
==> default: Chef 12.0.3 Omnibus package is already installed.
==> default: Running provisioner: chef_solo...
==> default: Detected Chef (latest) is already installed
Generating chef JSON and uploading...
==> default: Running chef-solo...
==> default: [2015-01-27T21:00:31+00:00] INFO: Forking chef instance to converge...
==> default: [2015-01-27T21:00:31+00:00] DEBUG: Fork successful. Waiting for new chef pid: 2977
==> default: [2015-01-27T21:00:31+00:00] DEBUG: Forked instance now converging
==> default: [2015-01-27T21:00:31+00:00] INFO: *** Chef 12.0.3 ***
==> default: [2015-01-27T21:00:31+00:00] INFO: Chef-client pid: 2977
==> default: [2015-01-27T21:00:31+00:00] DEBUG: Chef-client request_id: 03997806-45c2-4d61-a9ab-029c3960788e
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Building node object for property.ca
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Extracting run list from JSON attributes provided on command line
==> default: [2015-01-27T21:00:34+00:00] INFO: Setting the run_list to ["recipe[install]"] from CLI options
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Applying attributes from json file
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Platform is centos version 6.5
==> default: [2015-01-27T21:00:34+00:00] INFO: Run List is [recipe[install]]
==> default: [2015-01-27T21:00:34+00:00] INFO: Run List expands to [install]
==> default: [2015-01-27T21:00:34+00:00] INFO: Starting Chef Run for property.ca
==> default: [2015-01-27T21:00:34+00:00] INFO: Running start handlers
==> default: [2015-01-27T21:00:34+00:00] INFO: Start handlers complete.
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Re-raising exception: Chef::Exceptions::CookbookNotFound - Cookbook install not found. If you're loading install from another cookbook, make sure you configure the dependency in your metadata
==> default: /opt/chef/embedded/apps/chef/lib/chef/cookbook/cookbook_collection.rb:38:in `block in initialize'
==> default:   /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `yield'
==> default:   /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `default'
==> default:   /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `default'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:277:in `[]'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:277:in `each_cookbook_dep'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:255:in `add_cookbook_with_deps'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:88:in `block in cookbook_order'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:86:in `each'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:86:in `cookbook_order'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:71:in `compile'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/run_context.rb:92:in `load'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/client.rb:235:in `setup_run_context'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/client.rb:397:in `run'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:261:in `block in fork_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:215:in `block in run_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/local_mode.rb:38:in `with_server_connectivity'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:201:in `run_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:245:in `block in interval_run_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `loop'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `interval_run_chef_client'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:224:in `run_application'
==> default:   /opt/chef/embedded/apps/chef/lib/chef/application.rb:58:in `run'
==> default:   /opt/chef/embedded/apps/chef/bin/chef-solo:25:in `<top (required)>'
==> default:   /usr/bin/chef-solo:40:in `load'
==> default:   /usr/bin/chef-solo:40:in `<main>'
==> default: [2015-01-27T21:00:34+00:00] ERROR: Running exception handlers
==> default: [2015-01-27T21:00:34+00:00] ERROR: Exception handlers complete
==> default: [2015-01-27T21:00:34+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2015-01-27T21:00:34+00:00] DEBUG: Chef::Exceptions::CookbookNotFound: Cookbook install not found. If you're loading install from another cookbook, make sure you configure the dependency in your metadata
==> default: /opt/chef/embedded/apps/chef/lib/chef/cookbook/cookbook_collection.rb:38:in `block in initialize'
==> default: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `yield'
==> default: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `default'
==> default: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.0.1/lib/ohai/mash.rb:77:in `default'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:277:in `[]'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:277:in `each_cookbook_dep'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:255:in `add_cookbook_with_deps'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:88:in `block in cookbook_order'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:86:in `each'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:86:in `cookbook_order'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:71:in `compile'
==> default: /opt/chef/embedded/apps/chef/lib/chef/run_context.rb:92:in `load'
==> default: /opt/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
==> default: /opt/chef/embedded/apps/chef/lib/chef/client.rb:235:in `setup_run_context'
==> default: /opt/chef/embedded/apps/chef/lib/chef/client.rb:397:in `run'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:261:in `block in fork_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:249:in `fork_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:215:in `block in run_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/local_mode.rb:38:in `with_server_connectivity'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:201:in `run_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:245:in `block in interval_run_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `loop'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `interval_run_chef_client'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:224:in `run_application'
==> default: /opt/chef/embedded/apps/chef/lib/chef/application.rb:58:in `run'
==> default: /opt/chef/embedded/apps/chef/bin/chef-solo:25:in `<top (required)>'
==> default: /usr/bin/chef-solo:40:in `load'
==> default: /usr/bin/chef-solo:40:in `<main>'
==> default: [2015-01-27T21:00:34+00:00] ERROR: Cookbook install not found. If you're loading install from another cookbook, make sure you configure the dependency in your metadata
==> default: [2015-01-27T21:00:34+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.

非常感谢任何帮助。

编辑 - 答案

经过更多调查,在@coderanger 的帮助下,版本 1 似乎出现了问题。7.X 有时在后续 vagrant up --provision 命令中未创建 chef 共享目录的问题.我降级到 1.6.5,这似乎解决了问题。您可以在更改日志中看到问题 (https://github.com/mitchellh/vagrant/blob/master/CHANGELOG.md)

您的 Vagrant 或 Berkshelf 插件副本可能已过时。我没有看到 berks 创建的临时文件夹被设置为共享文件夹。检查您的 vagrant-berkshelf.

版本