Skip to content
Snippets Groups Projects
Select Git revision
  • da9b19a9f59c39110d5598500cfa82e2aac8f14e
  • main default protected
2 results

README.md

Blame
  • Vagrantfile 3.42 KiB
    # -*- mode: ruby -*-
    # # vi: set ft=ruby :
    
    require 'fileutils'
    
    Vagrant.require_version ">= 1.8.0"
    
    CONFIG = File.join(File.dirname(__FILE__), "vagrant/config.rb")
    
    # Defaults for config options defined in CONFIG
    $num_instances = 3
    $instance_name_prefix = "k8s"
    $vm_gui = false
    $vm_memory = 1536
    $vm_cpus = 1
    $shared_folders = {}
    $forwarded_ports = {}
    $subnet = "172.17.8"
    $box = "bento/ubuntu-14.04"
    
    host_vars = {}
    
    if File.exist?(CONFIG)
      require CONFIG
    end
    
    # if $inventory is not set, try to use example
    $inventory = File.join(File.dirname(__FILE__), "inventory") if ! $inventory
    
    # if $inventory has a hosts file use it, otherwise copy over vars etc
    # to where vagrant expects dynamic inventory to be.
    if ! File.exist?(File.join(File.dirname($inventory), "hosts"))
      $vagrant_ansible = File.join(File.dirname(__FILE__), ".vagrant",
                           "provisioners", "ansible")
      FileUtils.mkdir_p($vagrant_ansible) if ! File.exist?($vagrant_ansible)
      if ! File.exist?(File.join($vagrant_ansible,"inventory"))
        FileUtils.ln_s($inventory, $vagrant_ansible)
      end
    end
    
    Vagrant.configure("2") do |config|
      # always use Vagrants insecure key
      config.ssh.insert_key = false
      config.vm.box = $box
    
      # plugin conflict
      if Vagrant.has_plugin?("vagrant-vbguest") then
        config.vbguest.auto_update = false
      end
    
      (1..$num_instances).each do |i|
        config.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |config|
          config.vm.hostname = vm_name
    
          if $expose_docker_tcp
            config.vm.network "forwarded_port", guest: 2375, host: ($expose_docker_tcp + i - 1), auto_correct: true
          end
    
          $forwarded_ports.each do |guest, host|
            config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
          end
    
          ["vmware_fusion", "vmware_workstation"].each do |vmware|
            config.vm.provider vmware do |v|
              v.vmx['memsize'] = $vm_memory
              v.vmx['numvcpus'] = $vm_cpus
            end
          end
    
          config.vm.provider :virtualbox do |vb|