2

Here's my Packer file.

    {
    "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"
      }
    ]
  }

I run this and then get an SSH error as shown (with executing command)

$ 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

I've been looking at the Packer docs here https://www.packer.io/docs/provisioners/file.html regarding the file upload, and don't see anything about making an SSH connection, and also have been checking out the docs on remote ssh here https://www.packer.io/docs/provisioners/shell.html but still don't see what the issue is exactly that is causing the image to error out with the sh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain message.

I also added the communicator key and value to ssh per @tekjava suggested and still the same error. My builder looked like this after the addition.

{
  "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"
}
Adron
  • 614
  • 1
  • 8
  • 16

4 Answers4

4

There are some images on Google Cloud Engine that disable root ssh access by default. Centos, Debian, and the new Container-VM image seem to be among those. It seems to be solved by specifying a username to use:

"ssh_username": "anythingyoulike"

...which will then be created by Packer during the build.

2

If you have os login enabled at the project level, you may need to disable it for the packer VM, i.e., add this to your googlecompute builder config:

      "metadata": {
        "enable-oslogin": "FALSE"
      }
Ulf Adams
  • 121
  • 3
1

This appears to be related to this bug report on the packer repo. It's a fairly new bug, failing with Debian 8 images later then debian-8-jessie-v20160329. As a work-around, you can specify debian image debian-8-jessie-v20160329 and manually apply security updates.

Niklas B
  • 421
  • 1
  • 3
  • 8
0

Try using the SHH Communicator: https://www.packer.io/docs/templates/communicator.html

The SSH communicator connects to the host via SSH. If you have an SSH agent enabled on the machine running Packer, it will automatically forward the SSH agent to the remote host.

  • I tried this, unfortunately I've still been getting the same errors. The first attempt I just added the `"communicator": "ssh"` value to the *.json file I have above under the builders list of properties. I still go the same error. – Adron Jul 27 '16 at 23:35