vagrant-hostmanager (1.8.6) 更新来宾主机时出错?

vagrant-hostmanager (1.8.6) error when updating guest hosts?

我安装了 vag运行t-hostmanager 1.8.6,当我 运行 vagrant hostmanager 我最终遇到以下错误:

[vagrant-hostmanager:guest] Updating hosts file on the virtual machine puppet_server...
sh: 1: Syntax error: "(" unexpected

...并且 /etc/hosts 文件未更新。有办法解决这个问题吗?

这是我的 Vag运行t 文件:

Vagrant.configure(2) do |config|

  config.vm.box = "blah/turnkey-lamp-14.2"

  config.vm.provider "virtualbox" do |vb|
      vb.cpus = 2
      vb.gui = true
  end

  config.vm.boot_timeout = 10000
  config.vm.network "private_network", type: "dhcp"

  #config.vm.provision :hostmanager

  config.ssh.insert_key = false
  #config.ssh.private_key_path = "/mnt/vm_lab/vagrant_box_storage/.vagrant.d/insecure_private_key"
  config.ssh.forward_agent = true

  config.hostmanager.enabled = true
  config.hostmanager.manage_guest = true
  #config.hostmanager.manage_host = true

  config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
      if vm.id
         `VBoxManage guestproperty get #{vm.id} "/VirtualBox/GuestInfo/Net/1/V4/IP".split()[1]`
      end
  end

  config.vm.define :puppet_server do |srv|
      srv.vm.hostname = "puppet-server"
      srv.vm.network :private_network, ip: '10.0.3.15'
      srv.vm.provision "shell", inline: $puppetServerScript 
      srv.vm.synced_folder "src/puppet-server", "/etc/puppet", create: true

  end

  config.vm.define :bareOSdirector do |srv|
      srv.vm.hostname = "bareOSdirector"
      srv.vm.network :private_network, ip: '10.0.3.10'
      srv.vm.provision "shell", inline: $puppetClientBareOSdir
  end

  config.vm.define :webserver do |srv|
      srv.vm.hostname = "webserver"
      srv.vm.network :private_network, ip: '10.0.3.8'   
      srv.vm.provision "shell", inline: $puppetClientWebserver
  end
end

我以为是hosts文件本身的问题,清空了,重新运行命令,还是没有更新

sh: 1: Syntax error: "(" unexpected 结果是一个 shell 错误,因为 ruby 拆分意外地包含在 shell 命令中。

有 2 个问题...

  1. 语法有点错误,在 shell 和 ruby 语法之间的错误位置有一个 ```。
  2. 我得到的是错误卡的 IP 地址...

我尝试 运行 从命令行获取的命令:

VBoxManage guestproperty get "puppet_server" "/VirtualBox/GuestInfo/Net/1/V4/IP
Value: 172.x.x.x

它产生了错误的 IP 地址...所以我尝试了:

VBoxManage guestproperty get "puppet_server" "/VirtualBox/GuestInfo/Net/2/V4/IP
Value: 10.0.3.15

我得到了我期待的地址。

块:

  config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
      if vm.id
         `VBoxManage guestproperty get #{vm.id} "/VirtualBox/GuestInfo/Net/1/V4/IP".split()[1]`
      end
  end

应该是:

  config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
      if vm.id
         `VBoxManage guestproperty get #{vm.id} "/VirtualBox/GuestInfo/Net/2/V4/IP"`.split()[1]
      end
  end

然后把所有的机器都启动起来后,我又运行 vagrant hostmanager,所有的/etc/hosts文件都按预期填写了。