我是Packer的新手。我已经非常详细地研究了这个问题(上图)。我目前正在尝试创建一个UBuntu 32位VM。我在WIndows 10操作系统上运行Packer。一旦安装完成并且VM重新启动,然后我提示使用GUI登录我的VM,而打包器仍然运行我的主机Windows说它正在等待SSH可用。我怎样才能最好地使用ssh让Packer用来连接我的虚拟机。这是我的json.template
{
"builders": [
{
"type": "virtualbox-iso",
"vm_name": "{{ user `alias` }}",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--cpus", "1" ],
[ "modifyvm", "{{.Name}}", "--memory", "{{user `ram`}}" ],
[ "modifyvm", "{{.Name}}", "--clipboard", "bidirectional" ],
[ "modifyvm", "{{.Name}}", "--draganddrop", "bidirectional" ],
[ "modifyvm", "{{.Name}}", "--audio", "none" ],
[ "modifyvm", "{{.Name}}", "--nic1", "intnet"],
[ "modifyvm", "{{.Name}}","--nic2", "null"],
[ "modifyvm", "{{.Name}}","--vram", "16"],
[ "modifyvm", "{{.Name}}","--mouse", "usbtablet"]
],
"guest_os_type": "Ubuntu",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_checksum_type": "md5",
"disk_size": "{{ user `disk_size` }}",
"ssh_username": "{{ user `ssh_username` }}",
"ssh_password": "{{ user `ssh_password` }}",
"ssh_timeout": "{{ user `ssh_timeout` }}",
"guest_additions_mode": "attach",
"headless": "{{ user `headless` }}",
"boot_wait": "3s",
"boot_command": [
"<enter><wait><esc><enter><wait>",
"/install/vmlinuz<wait>",
" {{user `preseed_path`}}",
" debian-installer/locale=en_US console-setup/ask_detect=false<wait>",
" console-setup/layoutcode=us<wait>",
" keyboard-configuration/layoutcode=us<wait>",
" passwd/user-password={{ user `ssh_password` }}<wait>",
" passwd/user-password-again={{ user `ssh_password` }}<wait>",
" finish-install/reboot_in_progress=note<wait>",
" netcfg/use_autoconfig=false<wait>",
" cdrom-detect/eject boolean=false<wait>",
" initrd=/install/initrd.gz<wait>",
"<enter><wait>"
],
"shutdown_command": "sudo shutdown -h now"
}
],
"post-processors": [
{
"type": "vagrant",
"output": "C://{{ user `box_name` }}.box"
}
],
"variables": {
"headless": "false",
"iso_checksum": "7",
"iso_url": "{{file path}}",
"disk_size": "256000",
"alias": "packervm",
"box_name": "ubuntu_custom",
"ssh_timeout": "20m",
"ssh_username": "{{username}}",
"ssh_password": "{{password}}",
"preseed_path":"file=/cdrom/preseed/preseed.cfg",
"ram": "2048"
}
}
P.S是的,在来到这里并提出这个问题之前,我已经查看了模板。
答案 0 :(得分:2)
实际上,我明白了。这是将ssh_port设置为22,将ssh_address设置为我的vm地址,将ssh_skip_nat_mapping设置为true,然后将我的NIC卡从内部网络更改为hostonly然后进行配置的组合。
答案 1 :(得分:1)
您覆盖了Packers的网络设置,因此主机无法联系到来宾。要解决此问题,请删除以下两行:
[ "modifyvm", "{{.Name}}", "--nic1", "intnet"],
[ "modifyvm", "{{.Name}}","--nic2", "null"],