radekg / terraform-provisioner-ansible

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

Provisioning using a bastion does not work on a restricted shell #89

Closed mcanevet closed 5 years ago

mcanevet commented 6 years ago

Provisioning using a bastion requires access to the mkdir command because of this.

However, sometime the sysadmins who set up the bastion allowed only access to the ssh command, so that we can jump to the destination host.

It would be great if this provider could work without trying to store the SSH public keys of the destination host on the bastion.

radekg commented 6 years ago

Hey @mcanevet, thank you for the report. Would the assumption be that the bastion has the known hosts file preconfigured?

mcanevet commented 6 years ago

Unfortunately no. I still have the message saying that the authenticity of the host can't be established before first login to remote host.

radekg commented 6 years ago

The only thing I can think of, is the following:

Additionally, having ansible_ssh_settings.bastion_user_known_hosts_file and ansible_ssh_settings.user_known_hosts_file wouldn't hurt either. This way, the administrator could potentially provide a bastion host with known hosts file populated.

mcanevet commented 6 years ago

@radekg I think your solutions would work fine.

radekg commented 5 years ago

Hi @mcanevet, I'm about to merge https://github.com/radekg/terraform-provisioner-ansible/pull/94 which contains the code required for the above workflow.

The example sshagent-local-with-bastion is the closest reflecting the described setup. To validate that the insecure_... settings do what they supposed to, cd into thhat example directory and run:

terraform apply -var "ami_id=${TERRAFORM_PROVISIONER_ANSIBLE_AMI_ID}" \
  -var "region=${R_REGION}" -var "aws_admin_profile=${R_NAME}" \
  -var "vpc_cidr_block=${R_VPC_CIDR_BLOCK}" \
  -var "infrastructure_name=${R_NAME}-local" \
  -var "insecure_no_strict_host_key_checking=true"

Because it takes more than 30 seconds for the SSH to become available on the target, you will need a file like this one: https://github.com/radekg/terraform-provisioner-ansible/pull/94/files#diff-170acbfffb52268849488843675447d2R1.

It seems that the usual SSH options for timeout and retries are not respected, what matters is the timeout and retries from the config file.

Of course, you'll need to set the environment up, as described in Getting started.

radekg commented 5 years ago

Resolved with https://github.com/radekg/terraform-provisioner-ansible/pull/94.