Packer 超时等待 VirtualBox 的 SSH 错误
Packer Timeout waiting for SSH error with VirtualBox
虽然我可以在 VirtualBox 中手动 ssh,但 Packer 不知道 ssh 连接是否建立。
我遇到过同样的问题,但找不到任何解决方案。
我使用 packer 的目的是将我现有的 ovf 文件转换为 Digital Ocean droplet,以便我可以在我的 Digital Ocean 服务器中使用它。
template.json
{
"builders": [
{
"type": "virtualbox-ovf",
"source_path": "/Users/seoyoochan/Desktop/work/G4M_3.1.2_OVF_demo/G4M_centos6_demo.ovf",
"ssh_username": "root",
"ssh_password": "g4mg4m$$",
"boot_command":[
"root<return>",
"g4mg4m$$<return>"
],
"headless": true,
"boot_wait": "30s",
"ssh_wait_timeout": "10000s",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
}
],
"post-processors": ["vagrant"]
}
运行 没有调试选项的打包程序构建
➜ G4M_3.1.2_OVF_demo packer build template.json
virtualbox-ovf output will be in this color.
==> virtualbox-ovf: Downloading or copying Guest additions
virtualbox-ovf: Downloading or copying: file:///Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
==> virtualbox-ovf: Importing VM: /Users/seoyoochan/Desktop/work/G4M_3.1.2_OVF_demo/G4M_centos6_demo.ovf
==> virtualbox-ovf: Creating forwarded port mapping for SSH (host port 3249)
==> virtualbox-ovf: Starting the virtual machine...
==> virtualbox-ovf: Waiting 10s for boot...
==> virtualbox-ovf: Typing the boot command...
==> virtualbox-ovf: Waiting for SSH to become available...
==> virtualbox-ovf: Timeout waiting for SSH.
==> virtualbox-ovf: Unregistering and deleting imported VM...
==> virtualbox-ovf: Error deleting VM: VBoxManage error: VBoxManage: error: Cannot unregister the machine 'packer-virtualbox-ovf-1451547904' while it is locked
==> virtualbox-ovf: VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
==> virtualbox-ovf: VBoxManage: error: Context: "Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(aMedia))" at line 155 of file VBoxManageMisc.cpp
==> virtualbox-ovf: Deleting output directory...
Build 'virtualbox-ovf' errored: Timeout waiting for SSH.
==> Some builds didn't complete successfully and had errors:
--> virtualbox-ovf: Timeout waiting for SSH.
==> Builds finished but no artifacts were created.
当我运行处于调试模式时
==> virtualbox-ovf: Waiting for SSH to become available...
2015/12/31 17:43:48 packer-builder-virtualbox-ovf: 2015/12/31 17:43:48 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
2015/12/31 17:43:53 packer-builder-virtualbox-ovf: 2015/12/31 17:43:53 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
2015/12/31 17:43:58 packer-builder-virtualbox-ovf: 2015/12/31 17:43:58 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
这个错误的原因是因为 eth0 设备不存在,这是因为新的 MAC 地址没有被覆盖。
有2种解决方案:
1) 删除 /etc/udev/rules.d/70-persistent-net.rules
以获得新的 MAC 地址
或
2) 将 eth0
名称更改为 eth1
,例如 eth1
、eth2
、eth3
执行上述任一方法后,通过键入 reboot
重新启动来宾系统。
检查ifconfig -a
您将看到 eth0
或您选择的其他以太网名称。
虽然我可以在 VirtualBox 中手动 ssh,但 Packer 不知道 ssh 连接是否建立。
我遇到过同样的问题,但找不到任何解决方案。
我使用 packer 的目的是将我现有的 ovf 文件转换为 Digital Ocean droplet,以便我可以在我的 Digital Ocean 服务器中使用它。
template.json
{
"builders": [
{
"type": "virtualbox-ovf",
"source_path": "/Users/seoyoochan/Desktop/work/G4M_3.1.2_OVF_demo/G4M_centos6_demo.ovf",
"ssh_username": "root",
"ssh_password": "g4mg4m$$",
"boot_command":[
"root<return>",
"g4mg4m$$<return>"
],
"headless": true,
"boot_wait": "30s",
"ssh_wait_timeout": "10000s",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
}
],
"post-processors": ["vagrant"]
}
运行 没有调试选项的打包程序构建
➜ G4M_3.1.2_OVF_demo packer build template.json
virtualbox-ovf output will be in this color.
==> virtualbox-ovf: Downloading or copying Guest additions
virtualbox-ovf: Downloading or copying: file:///Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
==> virtualbox-ovf: Importing VM: /Users/seoyoochan/Desktop/work/G4M_3.1.2_OVF_demo/G4M_centos6_demo.ovf
==> virtualbox-ovf: Creating forwarded port mapping for SSH (host port 3249)
==> virtualbox-ovf: Starting the virtual machine...
==> virtualbox-ovf: Waiting 10s for boot...
==> virtualbox-ovf: Typing the boot command...
==> virtualbox-ovf: Waiting for SSH to become available...
==> virtualbox-ovf: Timeout waiting for SSH.
==> virtualbox-ovf: Unregistering and deleting imported VM...
==> virtualbox-ovf: Error deleting VM: VBoxManage error: VBoxManage: error: Cannot unregister the machine 'packer-virtualbox-ovf-1451547904' while it is locked
==> virtualbox-ovf: VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
==> virtualbox-ovf: VBoxManage: error: Context: "Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(aMedia))" at line 155 of file VBoxManageMisc.cpp
==> virtualbox-ovf: Deleting output directory...
Build 'virtualbox-ovf' errored: Timeout waiting for SSH.
==> Some builds didn't complete successfully and had errors:
--> virtualbox-ovf: Timeout waiting for SSH.
==> Builds finished but no artifacts were created.
当我运行处于调试模式时
==> virtualbox-ovf: Waiting for SSH to become available...
2015/12/31 17:43:48 packer-builder-virtualbox-ovf: 2015/12/31 17:43:48 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
2015/12/31 17:43:53 packer-builder-virtualbox-ovf: 2015/12/31 17:43:53 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
2015/12/31 17:43:58 packer-builder-virtualbox-ovf: 2015/12/31 17:43:58 [DEBUG] TCP connection to SSH ip/port failed: dial tcp 127.0.0.1:3581: getsockopt: connection refused
这个错误的原因是因为 eth0 设备不存在,这是因为新的 MAC 地址没有被覆盖。
有2种解决方案:
1) 删除 /etc/udev/rules.d/70-persistent-net.rules
以获得新的 MAC 地址
或
2) 将 eth0
名称更改为 eth1
,例如 eth1
、eth2
、eth3
执行上述任一方法后,通过键入 reboot
重新启动来宾系统。
检查ifconfig -a
您将看到 eth0
或您选择的其他以太网名称。