Vagrant 开发和生产的流浪准备金

Vagrant 开发和生产的流浪准备金,vagrant,Vagrant,我们开始使用Vagrant来设置开发环境。 现在,我们希望在生产/暂存中也使用相同的文件 当我使用包含virtualbox提供程序和gce的同一个Vagrant文件时,我得到了错误 An active machine was found with a different provider. Vagrant currently allows each machine to be brought up with only a single provider at a time. A future v

我们开始使用Vagrant来设置开发环境。 现在,我们希望在生产/暂存中也使用相同的文件

当我使用包含virtualbox提供程序和gce的同一个Vagrant文件时,我得到了错误

An active machine was found with a different provider. Vagrant
currently allows each machine to be brought up with only a single
provider at a time. A future version will remove this limitation.
Until then, please destroy the existing machine to up with a new
provider.

Machine name: default
Active provider: virtualbox
Requested provider: google
有没有办法让我在virtualbox和gce上游手好闲

Vagrant.has_plugin?("nugrant")
Vagrant.require_version ">= 1.6.3"

Vagrant.configure("2") do |config|  
  config.vm.provider "virtualbox"
  config.vm.box = "yungsang/boot2docker"

  config.vm.provider :google do |google, override|
    override.vm.box = "gce"    
    google.google_project_id = $GOOGLE_PROJECT_ID
    google.google_client_email = $GOOGLE_CLIENT_EMAIL
    google.google_key_location = $GOOGLE_KEY_LOCATION

    # Override provider defaults
    google.name = "name"
    google.image = "ubuntu-1404-trusty-v20141212"
    google.machine_type = "n1-standard-1"
    google.zone = "europe-west1-c"
    google.metadata = {'custom' => 'metadata', 'production' => 'app'}
    google.tags = ['vagrantbox', 'prod']

    override.ssh.username = $LOCAL_USER
    override.ssh.private_key_path = $LOCAL_SSH_KEY

    config.vm.define :prod do |prod|
        prod.vm.provision :shell, inline: 'echo I am executed in prod only!!'
    end
  end

  config.vm.synced_folder ".", "/vagrant"

  # Fix busybox/udhcpc issue
  config.vm.provision :shell do |s|
    s.inline = <<-EOT
      if ! grep -qs ^nameserver /etc/resolv.conf; then
        sudo /sbin/udhcpc
      fi
      cat /etc/resolv.conf
    EOT
  end

  # Adjust datetime after suspend and resume
  config.vm.provision :shell do |s|
    s.inline = <<-EOT
      sudo /usr/local/bin/ntpclient -s -h pool.ntp.org
      date
    EOT
  end

  # Login docker hub
  config.vm.provision :shell do |s|
    s.inline = "/usr/bin/docker $@"
    s.args   = ["login", "-u", config.user.docker.username, "-p", config.user.docker.password, "-e", config.user.docker.email]
  end

  config.vm.provision :docker do |d|    
    d.pull_images "nginx"
    d.pull_images "mongodb"
    d.pull_images "java"    
  end

  ACTICE_SPRING_PROFILE = "te"

  config.vm.provision :docker do |d|
   # provision docker stuff here 
  end

  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 443, host: 8443
end

正确的答案是要记住,您的Vagrantfile首先是一个Ruby程序,执行该程序将生成CLI子命令遍历的数据结构

因此,创建将供应器添加到配置中的函数,然后在“内部”中调用它们。比如说,

def provisioner_one(config)
    config.vm.provision :shell, 'echo hello'
end

Vagrant.configure('2') do |config|
    # stuff here
    config.vm.define 'dev' do |dev, override|
        # whatever else here

        provisioner_one(dev)

        # other stuff here
    end
    # more other stuff here
end
这将显示。

可能的副本
def provisioner_one(config)
    config.vm.provision :shell, 'echo hello'
end

Vagrant.configure('2') do |config|
    # stuff here
    config.vm.define 'dev' do |dev, override|
        # whatever else here

        provisioner_one(dev)

        # other stuff here
    end
    # more other stuff here
end