0

我安装了 vagrant-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文件未更新。有没有办法解决这个问题?

这是我的流浪文件:

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

我认为它与主机文件本身有关,所以我清空它并重新运行命令,但它仍然没有更新它。

4

1 回答 1

0

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文件都按预期填写了。

于 2017-06-15T04:18:36.887 回答