Vagrant - 消息:Psych :: SyntaxError:(<unknown>):在第9行第1列

时间:2016-05-23 08:13:28

标签: vagrant symfony

当我运行

vagrant up

我收到错误:

There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.

Path: /Users/darius/PhpstormProjects/api.notification.guru/Vagrantfile
Line number: 0
Message: Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning a simple key at line 9 column 1

vagrant文​​件如下所示:

# -*- mode: ruby -*-
# # vi: set ft=ruby :

require 'fileutils'

Vagrant.require_version ">= 1.6.0"

CLOUD_CONFIG_PATH = File.join(File.dirname(__FILE__), "cloud-config")
CONFIG = File.join(File.dirname(__FILE__), "vm-config.rb")
CA_CERT_PATH = File.join(File.dirname(__FILE__), "certs/domain.pem")

# Defaults for config options defined in CONFIG
$num_instances = 1
$instance_name_prefix = "core"
$update_channel = "stable"
$image_version = "current"
$enable_serial_logging = false
$share_home = false
$vm_gui = false
$vm_memory = 1024
$vm_cpus = 1
$shared_folders = {}
$forwarded_ports = {}

# 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

if File.exist?(CONFIG)
  require CONFIG
end

# Use old vb_xxx config variables when set
def vm_gui
  $vb_gui.nil? ? $vm_gui : $vb_gui
end

def vm_memory
  $vb_memory.nil? ? $vm_memory : $vb_memory
end

def vm_cpus
  $vb_cpus.nil? ? $vm_cpus : $vb_cpus
end

Vagrant.configure("2") do |config|
  # always use Vagrants insecure key
  config.ssh.insert_key = false

  config.vm.box = "coreos-%s" % $update_channel
  if $image_version != "current"
      config.vm.box_version = $image_version
  end
  config.vm.box_url = "http://%s.release.core-os.net/amd64-usr/%s/coreos_production_vagrant.json" % [$update_channel, $image_version]

  config.vm.provider :virtualbox do |v|
    # On VirtualBox, we don't have guest additions or a functional vboxsf
    # in CoreOS, so tell Vagrant that so it can be smarter.
    v.check_guest_additions = false
    v.functional_vboxsf     = false
  end

  # 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.provider :virtualbox do |vb|
        vb.name = "api.notification.guru-%s" % [vm_name]
      end

      config.vm.hostname = vm_name

      if $enable_serial_logging
        logdir = File.join(File.dirname(__FILE__), "log")
        FileUtils.mkdir_p(logdir)

        serialFile = File.join(logdir, "%s-serial.txt" % vm_name)
        FileUtils.touch(serialFile)

        config.vm.provider :virtualbox do |vb, override|
          vb.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
          vb.customize ["modifyvm", :id, "--uartmode1", serialFile]
        end
      end

      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

      config.vm.provider :virtualbox do |vb|
        vb.gui = vm_gui
        vb.memory = vm_memory
        vb.cpus = vm_cpus
      end

      ip = "172.17.3.#{i+100}"
      config.vm.network :private_network, ip: ip

      # Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM.
      config.vm.synced_folder ".", "/home/core/shared", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp,noatime']
      $shared_folders.each_with_index do |(host_folder, guest_folder), index|
        config.vm.synced_folder host_folder.to_s, guest_folder.to_s, id: "core-share%02d" % index, nfs: true, mount_options: ['nolock,vers=3,udp']
      end

      if $share_home
        config.vm.synced_folder ENV['HOME'], ENV['HOME'], id: "home", :nfs => true, :mount_options => ['nolock,vers=3,udp']
      end

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

      if File.exist?(CA_CERT_PATH)
        config.vm.provision :file, :source => "#{CA_CERT_PATH}", :destination => "/tmp/domain.pem"
        config.vm.provision :shell, :inline => "mv /tmp/domain.pem /etc/ssl/certs/domain.pem && update-ca-certificates > /dev/null", :privileged => true
      end
    end
  end
end

语法错误应该在第9行。我要求检查我的同事,他也使用了这个 - 他说线路是相同的,他没有得到错误。

我在其他类似的帖子中看到了检查yaml文件,但我不知道哪些文件。我不认为这个错误存在一些相关的问题。

它是一个symfony项目,我只看到来自vendor文件夹中某些包的yml文件。所以它应该没什么可做的。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

实际上它显示的是第9行而不是vagrantfile。它在早期的行中崩溃了:

discovery: https://discovery.etcd.io/<token>

然后我看到cloud-config文件有像

这样的冲突

&LT;&LT;&LT;&LT;&LT;&LT;&LT; HEAD

并且无法读取该文件。我不知道这些冲突是如何产生的,因为cloud-config不在git中。

但是在我从git cloud-config.dist文件中复制了这行后,有一个临时标签

vagrant up

并运行

def foo = bar?:baz

这个令牌被覆盖了,机器被推了出来。