G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 16th, 2015 515 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dir = File.dirname(File.expand_path(__FILE__))
  2. vagrant_home = (ENV['VAGRANT_HOME'].to_s.split.join.length > 0) ? ENV['VAGRANT_HOME'] : "#{ENV['HOME']}/.vagrant.d"
  3. vagrant_dot  = (ENV['VAGRANT_DOTFILE_PATH'].to_s.split.join.length > 0) ? ENV['VAGRANT_DOTFILE_PATH'] : "#{dir}/.vagrant"
  4.  
  5. require 'yaml'
  6. require "#{dir}/puphpet/ruby/deep_merge.rb"
  7.  
  8. configValues = YAML.load_file("#{dir}/puphpet/config.yaml")
  9.  
  10. if File.file?("#{dir}/puphpet/config-custom.yaml")
  11.   custom = YAML.load_file("#{dir}/puphpet/config-custom.yaml")
  12.   configValues.deep_merge!(custom)
  13. end
  14.  
  15. data = configValues['vagrantfile-local']
  16.  
  17. Vagrant.require_version '>= 1.6.0'
  18.  
  19. Vagrant.configure('2') do |config|
  20.   config.vm.box     = "#{data['vm']['box']}"
  21.   config.vm.box_url = "#{data['vm']['box_url']}"
  22.  
  23.   if data['vm']['hostname'].to_s.strip.length != 0
  24.     config.vm.hostname = "#{data['vm']['hostname']}"
  25.   end
  26.  
  27.   if data['vm']['network']['private_network'].to_s != ''
  28.     config.vm.network 'private_network', ip: "#{data['vm']['network']['private_network']}"
  29.   end
  30.  
  31.   data['vm']['network']['forwarded_port'].each do |i, port|
  32.     if port['guest'] != '' && port['host'] != ''
  33.       config.vm.network :forwarded_port, guest: port['guest'].to_i, host: port['host'].to_i, auto_correct: true
  34.     end
  35.   end
  36.  
  37.   if !data['vm']['post_up_message'].nil?
  38.     config.vm.post_up_message = "#{data['vm']['post_up_message']}"
  39.   end
  40.  
  41.   if Vagrant.has_plugin?('vagrant-hostmanager')
  42.     hosts = Array.new()
  43.  
  44.     if !configValues['apache']['install'].nil? &&
  45.         configValues['apache']['install'].to_i == 1 &&
  46.         configValues['apache']['vhosts'].is_a?(Hash)
  47.       configValues['apache']['vhosts'].each do |i, vhost|
  48.         hosts.push(vhost['servername'])
  49.  
  50.         if vhost['serveraliases'].is_a?(Array)
  51.           vhost['serveraliases'].each do |vhost_alias|
  52.             hosts.push(vhost_alias)
  53.           end
  54.         end
  55.       end
  56.     elsif !configValues['nginx']['install'].nil? &&
  57.            configValues['nginx']['install'].to_i == 1 &&
  58.            configValues['nginx']['vhosts'].is_a?(Hash)
  59.       configValues['nginx']['vhosts'].each do |i, vhost|
  60.         hosts.push(vhost['server_name'])
  61.  
  62.         if vhost['server_aliases'].is_a?(Array)
  63.           vhost['server_aliases'].each do |x, vhost_alias|
  64.             hosts.push(vhost_alias)
  65.           end
  66.         end
  67.       end
  68.     end
  69.  
  70.     if hosts.any?
  71.       if config.vm.hostname.to_s.strip.length == 0
  72.         config.vm.hostname = 'puphpet-dev-machine'
  73.       end
  74.  
  75.       config.hostmanager.enabled           = true
  76.       config.hostmanager.manage_host       = true
  77.       config.hostmanager.ignore_private_ip = false
  78.       config.hostmanager.include_offline   = false
  79.       config.hostmanager.aliases           = hosts
  80.     end
  81.   end
  82.  
  83.   if Vagrant.has_plugin?('vagrant-cachier')
  84.     config.cache.scope = :box
  85.   end
  86.  
  87.   data['vm']['synced_folder'].each do |i, folder|
  88.     if folder['source'] != '' && folder['target'] != ''
  89.       sync_owner = !folder['owner'].nil? ? folder['owner'] : 'www-data'
  90.       sync_group = !folder['group'].nil? ? folder['group'] : 'www-data'
  91.  
  92.       if folder['sync_type'] == 'nfs'
  93.         if Vagrant.has_plugin?('vagrant-bindfs')
  94.           config.vm.synced_folder "#{folder['source']}", "/mnt/vagrant-#{i}", id: "#{i}", type: 'nfs'
  95.           config.bindfs.bind_folder "/mnt/vagrant-#{i}", "#{folder['target']}", owner: sync_owner, group: sync_group, perms: "u=rwX:g=rwX:o=rD"
  96.         else
  97.           config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'nfs'
  98.         end
  99.       elsif folder['sync_type'] == 'smb'
  100.         config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}", type: 'smb'
  101.       elsif folder['sync_type'] == 'rsync'
  102.         rsync_args = !folder['rsync']['args'].nil? ? folder['rsync']['args'] : ['--verbose', '--archive', '-z']
  103.         rsync_auto = !folder['rsync']['auto'].nil? ? folder['rsync']['auto'] : true
  104.         rsync_exclude = !folder['rsync']['exclude'].nil? ? folder['rsync']['exclude'] : ['.vagrant/']
  105.  
  106.         config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
  107.           rsync__args: rsync_args, rsync__exclude: rsync_exclude, rsync__auto: rsync_auto, type: 'rsync', group: sync_group, owner: sync_owner
  108.       elsif data['vm']['chosen_provider'] == 'parallels'
  109.         config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
  110.           group: sync_group, owner: sync_owner, mount_options: ['share']
  111.       else
  112.         config.vm.synced_folder "#{folder['source']}", "#{folder['target']}", id: "#{i}",
  113.           group: sync_group, owner: sync_owner, mount_options: ['dmode=775', 'fmode=774']
  114.       end
  115.     end
  116.   end
  117.  
  118.   config.vm.usable_port_range = (data['vm']['usable_port_range']['start'].to_i..data['vm']['usable_port_range']['stop'].to_i)
  119.  
  120.   unless ENV.fetch('VAGRANT_DEFAULT_PROVIDER', '').strip.empty?
  121.     data['vm']['chosen_provider'] = ENV['VAGRANT_DEFAULT_PROVIDER'];
  122.   end
  123.  
  124.   if data['vm']['chosen_provider'].empty? || data['vm']['chosen_provider'] == 'virtualbox'
  125.     ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox'
  126.  
  127.     config.vm.provider :virtualbox do |virtualbox|
  128.       data['vm']['provider']['virtualbox']['modifyvm'].each do |key, value|
  129.         if key == 'memory'
  130.           next
  131.         end
  132.         if key == 'cpus'
  133.           next
  134.         end
  135.  
  136.         if key == 'natdnshostresolver1'
  137.           value = value ? 'on' : 'off'
  138.         end
  139.  
  140.         virtualbox.customize ['modifyvm', :id, "--#{key}", "#{value}"]
  141.       end
  142.  
  143.       virtualbox.customize ['modifyvm', :id, '--memory', "#{data['vm']['memory']}"]
  144.       virtualbox.customize ['modifyvm', :id, '--cpus', "#{data['vm']['cpus']}"]
  145.  
  146.       if data['vm']['provider']['virtualbox']['modifyvm']['name'].nil? ||
  147.         data['vm']['provider']['virtualbox']['modifyvm']['name'].empty?
  148.         if data['vm']['hostname'].to_s.strip.length != 0
  149.           virtualbox.customize ['modifyvm', :id, '--name', config.vm.hostname]
  150.         end
  151.       end
  152.     end
  153.   end
  154.  
  155.   if data['vm']['chosen_provider'] == 'vmware_fusion' || data['vm']['chosen_provider'] == 'vmware_workstation'
  156.     ENV['VAGRANT_DEFAULT_PROVIDER'] = (data['vm']['chosen_provider'] == 'vmware_fusion') ? 'vmware_fusion' : 'vmware_workstation'
  157.  
  158.     config.vm.provider :vmware_fusion do |v, override|
  159.       data['vm']['provider']['vmware'].each do |key, value|
  160.         if key == 'memsize'
  161.           next
  162.         end
  163.         if key == 'cpus'
  164.           next
  165.         end
  166.  
  167.         v.vmx["#{key}"] = "#{value}"
  168.       end
  169.  
  170.       v.vmx['memsize']  = "#{data['vm']['memory']}"
  171.       v.vmx['numvcpus'] = "#{data['vm']['cpus']}"
  172.  
  173.       if data['vm']['provider']['vmware']['displayName'].nil? ||
  174.         data['vm']['provider']['vmware']['displayName'].empty?
  175.         if data['vm']['hostname'].to_s.strip.length != 0
  176.           v.vmx['displayName'] = config.vm.hostname
  177.         end
  178.       end
  179.     end
  180.   end
  181.  
  182.   if data['vm']['chosen_provider'] == 'parallels'
  183.     ENV['VAGRANT_DEFAULT_PROVIDER'] = 'parallels'
  184.  
  185.     config.vm.provider 'parallels' do |v|
  186.       data['vm']['provider']['parallels'].each do |key, value|
  187.         if key == 'memsize'
  188.           next
  189.         end
  190.         if key == 'cpus'
  191.           next
  192.         end
  193.  
  194.         v.customize ['set', :id, "--#{key}", "#{value}"]
  195.       end
  196.  
  197.       v.memory = "#{data['vm']['memory']}"
  198.       v.cpus   = "#{data['vm']['cpus']}"
  199.  
  200.       if data['vm']['provider']['parallels']['name'].nil? ||
  201.         data['vm']['provider']['parallels']['name'].empty?
  202.         if data['vm']['hostname'].to_s.strip.length != 0
  203.           v.name = config.vm.hostname
  204.         end
  205.       end
  206.     end
  207.   end
  208.  
  209.   ssh_username = !data['ssh']['username'].nil? ? data['ssh']['username'] : 'vagrant'
  210.  
  211.   config.vm.provision 'shell' do |s|
  212.     s.path = 'puphpet/shell/initial-setup.sh'
  213.     s.args = '/vagrant/puphpet'
  214.   end
  215.   config.vm.provision 'shell' do |kg|
  216.     kg.path = 'puphpet/shell/ssh-keygen.sh'
  217.     kg.args = "#{ssh_username}"
  218.   end
  219.   config.vm.provision :shell, :path => 'puphpet/shell/install-ruby.sh'
  220.   config.vm.provision :shell, :path => 'puphpet/shell/install-puppet.sh'
  221.  
  222.   config.vm.provision :puppet do |puppet|
  223.     puppet.facter = {
  224.       'ssh_username'     => "#{ssh_username}",
  225.       'provisioner_type' => ENV['VAGRANT_DEFAULT_PROVIDER'],
  226.       'vm_target_key'    => 'vagrantfile-local',
  227.     }
  228.     puppet.manifests_path = "#{data['vm']['provision']['puppet']['manifests_path']}"
  229.     puppet.manifest_file  = "#{data['vm']['provision']['puppet']['manifest_file']}"
  230.     puppet.module_path    = "#{data['vm']['provision']['puppet']['module_path']}"
  231.  
  232.     if !data['vm']['provision']['puppet']['options'].empty?
  233.       puppet.options = data['vm']['provision']['puppet']['options']
  234.     end
  235.   end
  236.  
  237.   config.vm.provision :shell do |s|
  238.     s.path = 'puphpet/shell/execute-files.sh'
  239.     s.args = ['exec-once', 'exec-always']
  240.   end
  241.   config.vm.provision :shell, run: 'always' do |s|
  242.     s.path = 'puphpet/shell/execute-files.sh'
  243.     s.args = ['startup-once', 'startup-always']
  244.   end
  245.   config.vm.provision :shell, :path => 'puphpet/shell/important-notices.sh'
  246.  
  247.   customKey  = "#{dir}/puphpet/files/dot/ssh/id_rsa"
  248.   vagrantKey = "#{vagrant_dot}/machines/default/#{ENV['VAGRANT_DEFAULT_PROVIDER']}/private_key"
  249.  
  250.   if File.file?(customKey)
  251.     config.ssh.private_key_path = [
  252.       customKey,
  253.       "#{vagrant_home}/insecure_private_key"
  254.     ]
  255.    
  256.     if File.file?(vagrantKey) and ! FileUtils.compare_file(customKey, vagrantKey)
  257.       File.delete(vagrantKey)
  258.     end
  259.  
  260.     if ! File.directory?(File.dirname(vagrantKey))
  261.       FileUtils.mkdir_p(File.dirname(vagrantKey))
  262.     end
  263.  
  264.     if ! File.file?(vagrantKey)
  265.       FileUtils.cp(customKey, vagrantKey)
  266.     end
  267.   end
  268.  
  269.   if !data['ssh']['host'].nil?
  270.     config.ssh.host = "#{data['ssh']['host']}"
  271.   end
  272.   if !data['ssh']['port'].nil?
  273.     config.ssh.port = "#{data['ssh']['port']}"
  274.   end
  275.   if !data['ssh']['username'].nil?
  276.     config.ssh.username = "#{data['ssh']['username']}"
  277.   end
  278.   if !data['ssh']['guest_port'].nil?
  279.     config.ssh.guest_port = data['ssh']['guest_port']
  280.   end
  281.   if !data['ssh']['shell'].nil?
  282.     config.ssh.shell = "#{data['ssh']['shell']}"
  283.   end
  284.   if !data['ssh']['keep_alive'].nil?
  285.     config.ssh.keep_alive = data['ssh']['keep_alive']
  286.   end
  287.   if !data['ssh']['forward_agent'].nil?
  288.     config.ssh.forward_agent = data['ssh']['forward_agent']
  289.   end
  290.   if !data['ssh']['forward_x11'].nil?
  291.     config.ssh.forward_x11 = data['ssh']['forward_x11']
  292.   end
  293.   if !data['vagrant']['host'].nil?
  294.     config.vagrant.host = data['vagrant']['host'].gsub(':', '').intern
  295.   end
  296. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top