From c5120fdd5e2b90df9dad18cd803b02c7f7a4adcf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 30 Jan 2013 20:16:10 -0800 Subject: [PATCH] Don't fail too early with bad Vagrantfiles [GH-1345] --- lib/vagrant/environment.rb | 73 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index cab6e6f7a..c6c5f7e14 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -17,12 +17,6 @@ module Vagrant DEFAULT_LOCAL_DATA = ".vagrant" DEFAULT_RC = "~/.vagrantrc" - # This is the global config, comprised of loading configuration from - # the default, home, and root Vagrantfiles. This configuration is only - # really useful for reading the list of virtual machines, since each - # individual VM can override _most_ settings. - attr_reader :config_global - # The `cwd` that this environment represents attr_reader :cwd @@ -131,9 +125,6 @@ module Vagrant # Load the plugins load_plugins - - # Initialize the configuration. This will load our global configuration. - initialize_config end # Return a human-friendly string for pretty printed or inspected @@ -210,6 +201,42 @@ module Vagrant @_boxes ||= BoxCollection.new(boxes_path) end + # This is the global config, comprised of loading configuration from + # the default, home, and root Vagrantfiles. This configuration is only + # really useful for reading the list of virtual machines, since each + # individual VM can override _most_ settings. + # + # This is lazy-loaded upon first use. + # + # @return [Object] + def config_global + return @config_global if @config_global + + @logger.info("Initialzing config...") + + home_vagrantfile = nil + root_vagrantfile = nil + home_vagrantfile = find_vagrantfile(home_path) if home_path + root_vagrantfile = find_vagrantfile(root_path) if root_path + + # Create the configuration loader and set the sources that are global. + # We use this to load the configuration, and the list of machines we are + # managing. Then, the actual individual configuration is loaded for + # each {#machine} call. + @config_loader = Config::Loader.new(Config::VERSIONS, Config::VERSIONS_ORDER) + @config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root)) + @config_loader.set(:home, home_vagrantfile) if home_vagrantfile + @config_loader.set(:root, root_vagrantfile) if root_vagrantfile + + # Make the initial call to get the "global" config. This is mostly + # only useful to get the list of machines that we are managing. + # Because of this, we ignore any warnings or errors. + @config_global, _ = @config_loader.load([:default, :home, :root]) + + # Return the config + @config_global + end + # This returns a machine with the proper provider for this environment. # The machine named by `name` must be in this environment. # @@ -451,34 +478,6 @@ module Vagrant # Load Methods #--------------------------------------------------------------- - # This initializes the config loader for this environment. The config - # loader is cached so that prior Vagrantfiles aren't loaded multiple - # times. - def initialize_config - @logger.info("Initialzing config...") - - home_vagrantfile = nil - root_vagrantfile = nil - home_vagrantfile = find_vagrantfile(home_path) if home_path - root_vagrantfile = find_vagrantfile(root_path) if root_path - - # Create the configuration loader and set the sources that are global. - # We use this to load the configuration, and the list of machines we are - # managing. Then, the actual individual configuration is loaded for - # each {#machine} call. - @config_loader = Config::Loader.new(Config::VERSIONS, Config::VERSIONS_ORDER) - @config_loader.set(:default, File.expand_path("config/default.rb", Vagrant.source_root)) - @config_loader.set(:home, home_vagrantfile) if home_vagrantfile - @config_loader.set(:root, root_vagrantfile) if root_vagrantfile - - # Make the initial call to get the "global" config. This is mostly - # only useful to get the list of machines that we are managing. - # Because of this, we ignore any warnings or errors. - @config_global, _ = @config_loader.load([:default, :home, :root]) - - # Old order: default, box, home, root, vm - end - # This sets the `@home_path` variable properly. # # @return [Pathname]