使用Packer与Google Cloud并使用Debian Build获得SSH连接问题

这是我的Packer文件。

{ "variables": { "account_json": "{{env `packer_account_json`}}" }, "builders": [ { "type": "googlecompute", "account_file": "{{user `account_json`}}", "project_id": "united-course-124523", "source_image": "debian-8-jessie-v20160711", "zone": "us-central1-a", "instance_name": "hub-{{timestamp}}", "image_name": "hub-{{uuid}}", "image_description": "Elasticsearch 2.3.4." } ], "provisioners": [ { "type": "shell", "inline": [ "sleep 20", "echo \"slept for 20 seconds.\"" ] }, { "type": "file", "source": "../scripts/install-elastic.sh", "destination": "../scripts/install-elastic.sh" }, { "type": "shell", "script": "../scripts/install-elastic.sh", "pause_before": "3s" } ] } 

我运行这个,然后得到一个SSH错误,如图所示(执行命令)

 $ packer build elastic-2.3.4.json googlecompute output will be in this color. ==> googlecompute: Checking image does not exist... ==> googlecompute: Creating temporary SSH key for instance... ==> googlecompute: Creating instance... googlecompute: Loading zone: us-central1-a googlecompute: Loading image: debian-8-jessie-v20160711 in project united-course-124523 googlecompute: Loading machine type: n1-standard-1 googlecompute: Loading network: default googlecompute: Requesting instance creation... googlecompute: Waiting for creation operation to complete... googlecompute: Instance has been created! ==> googlecompute: Waiting for the instance to become running... googlecompute: IP: 104.197.225.237 ==> googlecompute: Waiting for SSH to become available... ==> googlecompute: Error waiting for SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain ==> googlecompute: Deleting instance... googlecompute: Instance has been deleted! ==> googlecompute: Deleting disk... googlecompute: Disk has been deleted! Build 'googlecompute' errored: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain 

我一直在看这里的file upload的包装文件https://www.packer.io/docs/provisioners/file.html ,并没有看到任何关于做SSH连接,也已经检查远程SSH文档在这里https://www.packer.io/docs/provisioners/shell.html但仍然没有看到是什么问题是正是导致图像错误与sh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain留言。

我也添加了沟通的关键和价值ssh每@tekjavabuild议,仍然是相同的错误。 添加后,我的build设者看起来像这样。

 { "type": "googlecompute", "account_file": "{{user `account_json`}}", "project_id": "united-course-124523", "source_image": "debian-8-jessie-v20160711", "zone": "us-central1-a", "instance_name": "{{user `instance_name`}}", "image_name": "elastic-{{uuid}}", "image_description": "Elasticsearch 2.3.4.", "communicator": "ssh" } 

Google Cloud Engine上有一些图片默认禁用root ssh访问权限。 Centos,Debian和新的Container-VM映像似乎都在其中。 这似乎是通过指定一个用户名来解决:

"ssh_username": "anythingyoulike"

…在构build过程中将由Packer创build。

尝试使用SHH通讯器: https : //www.packer.io/docs/templates/communicator.html

SSH通信器通过SSH连接到主机。 如果您在运行Packer的计算机上启用了SSH代理,则会自动将SSH代理转发到远程主机。

这似乎与这个关于打包回购的错误报告有关。 这是一个相当新的bug,在Debian 8映像后面debian-8-jessie-v20160329 。 作为解决方法,您可以指定debian debian-8-jessie-v20160329 image debian-8-jessie-v20160329并手动应用安全更新。