# Ansible & AWS ec2-instance-connect - cannot SSH

**URL:** <https://forum.ansible.com/t/ansible-aws-ec2-instance-connect-cannot-ssh/4998>\
**Category:** Get Help\
**Tags:** ssh, aws\
**Created:** [April 17, 2024, 2:31pm UTC](https://forum.ansible.com/t/ansible-aws-ec2-instance-connect-cannot-ssh/4998 "2024-04-17T14:31:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [April 17, 2024, 2:31pm UTC](https://forum.ansible.com/t/ansible-aws-ec2-instance-connect-cannot-ssh/4998/1 "2024-04-17T14:31:03Z")

</div>

Hello, has anyone ever used AWS `ec2-instance-connect` with Ansible to connect to servers, using a ProxyCommand in `ansible_ssh_common_args` ? I cannot get Ansible to SSH to the server. When I run the straight aws command from the ansible server, connects fine.

Full details in pastebin links below, but some small context:

Playbook Task:

```auto
- name: Create tomcat group
  become: true
  ansible.builtin.group:
    name: tomcat
    gid: 2001
    state: present

```

`group_vars` settings:

```auto
ansible_user: ansible
ansible_ssh_private_key_file: /opt/ansible/keys/ansible.pem
 
ansible_ssh_common_args: '-o ProxyCommand="aws ec2-instance-connect ssh --region us-east-1 --instance-id {{ instance_id }} --os-user {{ ansible_user }} --private-key-file {{ ansible_ssh_private_key_file }}"'

```

Errors:

```auto
    -bash: line 1: $'SSH-2.0-OpenSSH_8.7\r': command not found
    Connection timed out during banner exchange
    Connection to UNKNOWN port 65535 timed out

```

Full Details:  
Ansible Version / Playbook / `group_vars` settings: [Ansible Version / Playbook / group\_vars - Pastebin.com](https://pastebin.com/chvjJD1C)

Playbook error (`-vvvv` ): [Create Tomcat Group Error - -vvvv Results - Pastebin.com](https://pastebin.com/yrxLV5jj)

Successful connection using just the Proxy Command / aws call: [AWS ec2-instance-connect - Pastebin.com](https://pastebin.com/MPap74wQ)

Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [July 25, 2024, 9:04pm UTC](https://forum.ansible.com/t/ansible-aws-ec2-instance-connect-cannot-ssh/4998/2 "2024-07-25T21:04:32Z")

</div>

This was never really resolved, but 2 findings will cause me to close this out:

1. Could never get the `ec2-instance-connect ssh` ProxyCommand to work. Ended up using `ec2-instance-connect open-tunnel --instance-id XXX`
2. Turns out EC2 Instance Connect shouldn’t really be used with Ansible - they SEVERELY limit the bandwidth going through Instance Connect One example is when I tried to copy 2 files that were less than 2 GB, I found that within same region it was ~3,000x slower, and across region it never finished

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 24, 2024, 9:04pm UTC](https://forum.ansible.com/t/ansible-aws-ec2-instance-connect-cannot-ssh/4998/3 "2024-08-24T21:04:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
