# Ansible as a Packer provisioner hanging?

**URL:** <https://forum.ansible.com/t/ansible-as-a-packer-provisioner-hanging/30924>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [July 31, 2019, 11:14pm UTC](https://forum.ansible.com/t/ansible-as-a-packer-provisioner-hanging/30924 "2019-07-31T23:14:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bob/32/9260_2.png) [@bob](https://forum.ansible.com/u/bob)\
**Post date:** [July 31, 2019, 11:14pm UTC](https://forum.ansible.com/t/ansible-as-a-packer-provisioner-hanging/30924/1 "2019-07-31T23:14:10Z")

</div>

Trying to use ansible as a provisioner in packer. Ansible is hanging during the TASK [Gathering Facts] and I have no idea why

```json
the provisioner is below:

{
"type": "ansible",
"command": "script/ansible.sh",
"playbook_file": "playbooks/testing_ami.yml",
"user": "{{ user `ssh_username` }}",
"groups": [
"aws_comap_com",
"linux_servers"
],
"extra_arguments": [
"-u ubuntu",
"-vvvv"
],
"only": [
"amazon-ebs"
]
}

```

The testing\_ami.yml is below:

```yaml
- hosts: all
vars:
keep_deb_src: true
keep_build_essentials: true
pre_tasks:
roles:
- { role: take-over, become: yes }
tasks:
post_tasks:

```

The script/ansible.sh

```bash
#!/bin/bash

ansible-playbook $@

```

I do not understand why a couple of the ssh calls to the packer AMI work and then last one fails.

I do not even know if this is an ansible problem as invoking the same playbook from the command line  
works as expected. BUT the logs show the invocation of ansible-playbook like I would do via the command  
line.

gist of the logs

[https://gist.github.com/basictheprogram/017998412e0dc7aa068ee765cdd85ad5](https://gist.github.com/basictheprogram/017998412e0dc7aa068ee765cdd85ad5)

---

<div class="post-metadata">

**Author:** ![bob](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bob/32/9260_2.png) [@bob](https://forum.ansible.com/u/bob)\
**Post date:** [August 1, 2019, 3:26am UTC](https://forum.ansible.com/t/ansible-as-a-packer-provisioner-hanging/30924/2 "2019-08-01T03:26:46Z")

</div>

I can ssh to the public IP address of the Packer AMI but Ansible being run as a provisioner in Packer shows this log:

amazon-ebs: \<127.0.0.1\> ESTABLISH SSH CONNECTION FOR USER: ubuntu  
amazon-ebs: \<127.0.0.1\> SSH: EXEC ssh -vvv -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o Port=50328 -o ‘IdentityFile=“/var/folders/y\_/w\_pbl7355vg3gv5xkmsld49m0000gn/T/ansible-key347004316”’ -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ‘User=“ubuntu”’ -o ConnectTimeout=10 127.0.0.1 ‘/bin/sh -c ‘"’"’/usr/bin/python3.6 && sleep 0’“'”‘’  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 SSH proxy: accepted connection  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 authentication attempt from 127.0.0.1:50333 to 127.0.0.1:50328 as ubuntu using none  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 authentication attempt from 127.0.0.1:50333 to 127.0.0.1:50328 as ubuntu using publickey  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 new env request: LANG=en\_US.UTF-8  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 new exec request: /bin/sh -c ‘/usr/bin/python3.6 && sleep 0’  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 [INFO] 1234 bytes written for ‘stdin’  
2019/07/31 22:18:52 [INFO] 1234 bytes written for ‘stdin’  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 [DEBUG] Opening new ssh session  
2019/07/31 22:18:52 packer: 2019/07/31 22:18:52 [DEBUG] starting remote command: /bin/sh -c ‘/usr/bin/python3.6 && sleep 0’

As I understand it Packer running an ssh proxy

$ telnet localhost port  
Trying 127.0.0.1…  
Connected to localhost.  
Escape character is ‘^]’.  
SSH-2.0-Go

So Packer (Go) is being a proxy to the Packer AMI but I never see any sort of login attempts in /var/log/syslog on the Packer AMI then I try to “ssh 127.0.0.1 port”

Even more weird, in a terminal windows, not trying to run python, just attempting to get a shell (complete log at [https://gist.github.com/basictheprogram/3696f33543a0edc7eacdee76c54c8452](https://gist.github.com/basictheprogram/3696f33543a0edc7eacdee76c54c8452))

shell request failed on channel 0

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 1, 2019, 2:50pm UTC](https://forum.ansible.com/t/ansible-as-a-packer-provisioner-hanging/30924/3 "2019-08-01T14:50:19Z")

</div>

This is being tracked in [https://github.com/ansible/ansible/issues/57542](https://github.com/ansible/ansible/issues/57542)

The problem is that Ansible ssh pipelining does not work with the packer ssh proxy. To a further extent, the new python interpreter discovery in ansible 2.8 uses pipelining.

You can set ansible\_python\_interpreter=/usr/bin/python3.6 (or whatever interpreter you want to use), and then also ensure that you have pipelining turned off.
