Module: Gusteau::Vagrant
Instance Method Summary collapse
- #define_nodes(config, options, prefix = nil) ⇒ Object
- #define_provisioner(instance, node) ⇒ Object
- #define_vm(config, node, options) ⇒ Object
- #detect(config) {|options| ... } ⇒ Object
- #vm_config(node, options) ⇒ Object
Methods included from Log
Instance Method Details
#define_nodes(config, options, prefix = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/gusteau/vagrant.rb', line 19 def define_nodes(config, , prefix = nil) Gusteau::Config.read([:config_path] || ".gusteau.yml") Gusteau::Config.nodes.each_pair do |name, node| if node.config['server']['vagrant'] define_vm config, node, end end end |
#define_provisioner(instance, node) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/gusteau/vagrant.rb', line 82 def define_provisioner(instance, node) instance.vm.provision 'chef_solo' do |chef| chef.data_bags_path = 'data_bags' chef.cookbooks_path = Gusteau::Config.settings['cookbooks_path'] chef.roles_path = Gusteau::Config.settings['roles_path'] chef.json = node.config['attributes'] || {} chef.run_list = node.config['run_list'] || [] end end |
#define_vm(config, node, options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gusteau/vagrant.rb', line 58 def define_vm(config, node, ) vm_config = vm_config(node, ) config.vm.define vm_config[:name] do |instance| instance.vm.box = vm_config[:box] instance.vm.box_url = vm_config[:box_url] instance.vm.provider :virtualbox do |vb| vb.customize ['modifyvm', :id, '--memory', vm_config[:memory], '--name', vm_config[:label], '--cpus', vm_config[:cpus], '--natdnsproxy1', 'on' ] end if vm_config[:ip] instance.vm.network :private_network, :ip => vm_config[:ip] end define_provisioner(instance, node) if [:provision] end end |
#detect(config) {|options| ... } ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/gusteau/vagrant.rb', line 11 def detect(config) = Hashie::Mash.new .defaults = Hashie::Mash.new yield if block_given? define_nodes(config, .to_hash.symbolize_keys) end |
#vm_config(node, options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gusteau/vagrant.rb', line 29 def vm_config(node, ) defaults = [:defaults] || {} config = node.config['server']['vagrant'] label = [:prefix] ? "#{[:prefix]}-#{node.name}" : node.name config = {} if config == true box_url = config.fetch 'box_url' do unless defaults[:box_url] raise "Box url can't be determined for #{node.name}" end defaults[:box_url] end # If no one set the VirtualBox box name explicitly, use the end of the box_url # as the box name box_name = config.fetch('box', defaults[:box] || box_url.sub(/.*\/([^\/]+).box$/,'\1')) { :name => node.name, :label => label, :box => box_name, :box_url => box_url, :ip => config['IP'] || defaults[:ip], :cpus => config['cpus'] || defaults[:cpus] || 1, :memory => config['memory'] || defaults[:memory] || 1024 } end |