Skip to content

Issues with ansible provisioner with cloud builder and local ssh proxy #6379

@sivel

Description

@sivel

Ansible bug report: ansible/ansible#41377

Packer Version: 1.2.4
Host Platform: macOS
Debug Log: https://gist.github.com/sivel/483fd134f4d8552d6a521901b5265e5c

In the above mentioned bug report, the packer file is defined as:

{
  "min_packer_version": "1.2.3",
  "builders": [
    {
      "type": "googlecompute",
      "ssh_username": "packer",
      "project_id": "<YOUR_PROJECT_ID>",
      "source_image": "ubuntu-1604-xenial-v20180522",
      "zone": "us-central1-f",
      "image_family": "repro-image",
      "image_name": "repro-bug-{{isotime | clean_image_name}}",
      "disk_type": "pd-ssd"
    }
  ],
  "provisioners": [
    {
      "type": "ansible",
      "playbook_file": "./repro-image-playbook.yml",
      "extra_arguments": [
        "--ssh-extra-args",
        "-o IdentitiesOnly=yes"
      ]
    }
  ]
}

We can see the googlecompute builder defines "ssh_username": "packer", however the ansible provisioner does not define a user.

When packer creates the local ssh proxy for communicating with the google compute instance, it utilizes the packer user. Due to no user being supplied for the ansible provisioner, an inventory is created that looks like the following where ansible_user becomes defined as daniel.

default ansible_host=127.0.0.1 ansible_user=daniel ansible_port=51644

The remote host does not have a user daniel, however due to the way that the local proxy seems to work, an ssh command specifying -o User=daniel is ignored, and ssh connects through the proxy to the remote instance as the packer user.

Later, when ansible attempts to perform temp dir building, it executes echo ~daniel, which fails to expand due to the lack of the daniel user, and produces a literal ~daniel.

In the end this causes issues, as a directory is created at /home/packer/~daniel, and commands may fail to find the correct directory when using ~daniel as it is not an absolute path.

This situation would not be possible without the local ssh proxy, that ignores the -o User=daniel configuration. Otherwise, the connection would have failed with an auth error.

As it stands, this allowed ansible to think it was connecting as daniel, but really connected as packer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    community-supported-plugindenotes requests for plugins that are supported by the community, not by HashiCorp engineersprovisioner/ansible-remotestage/thinkingFlagged for internal discussions about possible enhancements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions