radekg / terraform-provisioner-ansible

Ansible with Terraform 0.14.x
Apache License 2.0
572 stars 100 forks source link

Failed to connect to the host via ssh: invalid format #95

Closed sjwl closed 5 years ago

sjwl commented 5 years ago

For some reason when a terraform variable storing the ssh key is passed in via an environment variable, there are some extra bits at the end of the key by the time it reaches terraform-provisioner-ansible.

Steps to reproduce

    connection {
        type = "ssh"
        user = "ubuntu"
        private_key = "${var.ssh_private_key}"
        //private_key = "${file("~/.ssh/id_rsa")}"  WORKS
    }
  1. export TF_VAR_ssh_private_key="$(cat ~/.ssh/id_rsa)"
  2. terraform apply

Expected behavior

Ansible provisioner executes without error

Actual behavior

openstack_compute_instance_v2.infra (ansible): TASK [Gathering Facts] *********************************************************
openstack_compute_instance_v2.infra (ansible): fatal: [(ip redacted)]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Load key \"/private/var/folders/kt/8r8l44m54159f_r1k0qwsmmm0000gp/T/b660abc6-f02b-4210-b36f-72a0a3e3fea1845955416\": invalid format\r\nubuntu@(ip redacted): Permission denied (publickey).\r\n", "unreachable": true}

Configuration

Terraform version: v0.11.10

DanielMarquard commented 5 years ago

We're getting a similar error, but we're passing the private key from a tls_private_key resource. This only happens when we use the local Ansible provisioner.

Any chance the two are related?

fatal: [IP redacted]: UNREACHABLE! => {"changed": false, "msg": "argument must be an int, or have a fileno() method", "unreachable": true}

Edit: I shouldn't hijack your issue, so I made one in case they're unrelated; #98.