使用CoreOS进行Vagrant多个VM配置

时间:2015-03-16 11:51:27

标签: vagrant vagrantfile coreos

我想要做的是,将标准的CoreOS Vagrantfile found here和我自己的Vagrantfile集成在一起,它可以启动Ubuntu框。

这是我的Vagrantfile:

# Vagrantfile API/syntax version.
VAGRANTFILE_API_VERSION = "2"

### Check if required plugins are installed
unless Vagrant.has_plugin?("vagrant-bindfs")
  raise 'vagrant-bindfs plugin is missing!'
end

unless Vagrant.has_plugin?("vagrant-hostsupdater")
  raise 'vagrant-hostsupdater plugin is missing!'
end


# Setup CoreOS config files
CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "user-data")
CONFIG = File.join(File.dirname(__FILE__), "config.rb")

# Defaults for config options defined in CONFIG
$num_instances = 1
$instance_name_prefix = "core"
$update_channel = "stable"


# Attempt to apply the deprecated environment variable NUM_INSTANCES to
# $num_instances while allowing config.rb to override it
if ENV["NUM_INSTANCES"].to_i > 0 && ENV["NUM_INSTANCES"]
  $num_instances = ENV["NUM_INSTANCES"].to_i
end

# Include Config file
if File.exist?(CONFIG)
  require CONFIG
end


Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# COREOS
  config.vm.define :coreos do |node|
    node.ssh.insert_key = false
    node.vm.box = "coreos-%s" % $update_channel
    node.vm.box_version = ">= 308.0.1"
    node.vm.box_url = "http://%s.release.core-os.net/amd64-usr/current/coreos_production_vagrant.json" % $update_channel

    node.vm.provider :virtualbox do |v|
      v.check_guest_additions = false
      v.functional_vboxsf     = false
    end

    if Vagrant.has_plugin?("vagrant-vbguest") then
      node.vbguest.auto_update = false
    end

    (1..$num_instances).each do |i|
      node.vm.define vm_name = "%s-%02d" % [$instance_name_prefix, i] do |node|
        node.vm.hostname = vm_name
        ip = "172.17.8.#{i+100}"
        node.vm.network :private_network, ip: ip

        if File.exist?(CLOUD_CONFIG_PATH)
          node.vm.provision :file, :source => "#{CLOUD_CONFIG_PATH}", :destination => "/tmp/vagrantfile-user-data"
          node.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
        end
      end
    end
  end


# UBUNTU

  config.vm.define :ubuntu do |node|
    node.vm.box = "ubuntu1404-64"
    node.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
    node.vm.network "private_network", ip: "192.168.100.100"
    node.vm.hostname = "wpthor"
    node.bindfs.debug = true

  ### Set a right amount of memory
    node.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "1024"]
    end


  ### Fix for Ansible bug resulting in an encoding error
    ENV['PYTHONIOENCODING'] = "utf-8"

  ### Run Ansible provision
    node.vm.provision "ansible" do |ansible|
      ansible.limit = 'all'
      ansible.verbose = "" ### If you notice errors, add "vvv" here to activate verbose mode
      ansible.playbook = "ansible/development.yml"
      ansible.inventory_path = "ansible/hosts"
    end
  end
end

它没有错误,但它只引导一个CoreOS节点(而不是3个)。可能这是一个愚蠢的语法错误,但我无法提出解决方案。你能救我吗?

1 个答案:

答案 0 :(得分:0)

只需更新要启动的计算机数量。

$num_instances = 3