Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Commit

Permalink
Allow empty config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
thom8 committed Feb 2, 2016
1 parent 777e336 commit 31c371b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Vagrant.require_version '>= 1.8.0'

cwd = File.dirname(File.expand_path(__FILE__))
config_dir = '.beetbox/'
vagrant_config = "#{cwd}/#{config_dir}config.yml"
project_config = "#{cwd}/#{config_dir}config.yml"
local_config = "#{cwd}/#{config_dir}local.config.yml"

# Default vagrant config.
Expand All @@ -20,19 +20,20 @@ vconfig = {
'beet_domain' => cwd.split('/').last.gsub(/[\._]/, '-') + ".local"
}

if !File.exist?(vagrant_config)
if !File.exist?(project_config)
# Create default config file.
require 'fileutils'
FileUtils::mkdir_p config_dir
File.open(vagrant_config, "w+") {|f| f.write("---\nbeet_domain: #{vconfig['beet_domain']}\n") }
File.open(project_config, "w+") {|f| f.write("---\nbeet_domain: #{vconfig['beet_domain']}\n") }
end

vconfig = vconfig.merge YAML::load_file(vagrant_config)
pconfig = YAML::load_file(project_config)
vconfig = vconfig.merge pconfig if !pconfig.nil?

# Merge local.config.yml
if File.exist?(local_config)
lconfig = YAML::load_file(local_config)
vconfig = vconfig.merge lconfig
vconfig = vconfig.merge lconfig if !lconfig.nil?
end

# Replace variables in YAML config.
Expand Down Expand Up @@ -98,8 +99,8 @@ Vagrant.configure("2") do |config|
end

# Upload vagrant.config.yml
node.vm.provision "vagrant_config", type: "file" do |s|
s.source = vagrant_config
node.vm.provision "project_config", type: "file" do |s|
s.source = project_config
s.destination = "#{vconfig['beet_home']}/ansible/vagrant.config.yml"
end

Expand Down

0 comments on commit 31c371b

Please sign in to comment.