使用Packer构建RancherOS时SSH连接失败

4
我在使用Packer和RancherOS时遇到了问题。我正在尝试使用cloud-config文件构建自定义的RancherOS镜像。我正在MacOSX上工作。 我有一个名为build.json的文件。
{
    "variables": {
        "vm_name" : ""
    },
    "builders": [
        {
            "type": "vmware-iso",
            "iso_url": "rancheros.iso",
            "guest_os_type": "other",
            "iso_checksum_type": "md5",
            "iso_checksum": "467caa8394684ba54e8731aed8480652",
            "output_directory": "output_rancheros",
            "ssh_wait_timeout": "30s",
            "shutdown_command": "sudo shutdown -h now",
            "disk_size": 20000,
            "ssh_username": "rancher",
            "ssh_password": "rancher",
            "ssh_port": 22,
            "ssh_wait_timeout": "90m",
            "vm_name": "{{ user `vm_name` }}",
            "boot_wait": "10s",
            "vmx_data": {
                "memsize": "4096"
            }
        }
    ],
    "provisioners": [
        {
            "type":"file",
            "source": "cloud-config.yml",
            "destination": "/tmp/cloud-config.yml"
        },
        {
            "type": "shell",
            "inline": [
                "sudo ros install -d /dev/sda -f -t generic -c /tmp/cloud-config.yml"
            ]
        }
    ]
}

我有一个名为cloud-config.yml的文件,其中只包含我的SSH密钥。

#cloud-config
ssh_authorized_keys:
    - ssh-rsa AAAA....d admin@example.com

当我执行构建命令packer build build.json时,我得到了以下结果:

    vmware-iso: + umount /mnt/new_img
    vmware-iso: time="2016-07-27T05:52:35Z" level=fatal msg=EOF
    vmware-iso: Continue with reboot [y/N]:
==> vmware-iso: Stopping virtual machine...
==> vmware-iso: Deleting output directory...
Build 'vmware-iso' errored: Script exited with non-zero exit status: 1

==> Some builds didn't complete successfully and had errors:
--> vmware-iso: Script exited with non-zero exit status: 1

==> Builds finished but no artifacts were created.

如果我理解得正确,我的脚本能够正常工作,但是当虚拟机重启后,新的SSH密钥就无法使用了。
我不知道该如何解决这个问题,希望有人能够帮助我。
最好的问候。

你是否遇到了Packer SSH超时的问题?我使用几乎相同的JSON(除了使用VBox而不是VMware),但无法通过SSH连接。错误信息:“Build 'virtualbox-iso' errored: ssh: handshake failed: ssh: unable to authenticate, attempted methods [password keyboard-interactive none], no supported methods remain”。 - Roman Mik
我从未尝试过使用VirtualBox,你能在StackOverflow上创建一个帖子让我帮忙吗?我至少需要template.json文件。 - severin.julien
握手失败:SSH无法验证,尝试的方法为“none”和“password”。谢谢。 - Roman Mik
1个回答

6

我找到了一个解决方案

只需在sudo ros install -d /dev/sda -f -t generic -c /tmp/cloud-config.yml命令上添加一个-no-reboot标志即可。

这样,在生成过程中就不会重新启动。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接