# Consistent docker\_image module failure on ec2 instances

**URL:** <https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650>\
**Category:** Ansible Project\
**Tags:** ubuntu, aws\
**Created:** [October 30, 2014, 9:43pm UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650 "2014-10-30T21:43:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ananda\_Debnath](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Ananda\_Debnath](https://forum.ansible.com/u/Ananda_Debnath)\
**Post date:** [October 30, 2014, 9:43pm UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650/1 "2014-10-30T21:43:46Z")

</div>

Gurus,

I’m trying to create a docker image from a Dockerfile in an ec2 instance. I’m able to create the ec2 instances and copy over the dockerfile fine. However, for _every_ ec2 instance I fire up, it _always_ fails the first time I try to build the docker image.

- name: Build the docker Nginx image  
docker\_image:  
path: “{{ docker\_nginx\_dir }}”  
state: build  
name: “grid/nginx”

The ansible failure stack trace looks like:  
failed: [54._XX.XX.XX_] =\> {“failed”: true, “parsed”: false}  
invalid output was: SUDO-SUCCESS-bdbbnpaupjsbudcxajoycrwmbmlehwux  
Traceback (most recent call last):  
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1414698075.43-175058707465136/docker\_image”, line 1455, in   
main()  
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1414698075.43-175058707465136/docker\_image”, line 220, in mai n  
image\_id = manager.build()  
File “/home/ec2-user/.ansible/tmp/ansible-tmp-1414698075.43-175058707465136/docker\_image”, line 143, in bui ld  
chunk\_json = json.loads(chunk)  
File “/usr/lib64/python2.6/json/ **init**.py”, line 307, in loads  
return \_default\_decoder.decode(s)  
File “/usr/lib64/python2.6/json/decoder.py”, line 322, in decode  
raise ValueError(errmsg(“Extra data”, s, end, len(s)))  
ValueError: Extra data: line 1 column 87 - line 1 column 52865 (char 87 - 52865)  
OpenSSH\_6.2p2 Ubuntu-6ubuntu0.4, OpenSSL 1.0.1e 11 Feb 2013  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug1: /etc/ssh/ssh\_config line 19: Applying options for \*  
debug1: auto-mux: Trying existing master  
debug2: fd 3 setting O\_NONBLOCK  
debug2: mux\_client\_hello\_exchange: master version 4  
debug3: mux\_client\_forwards: request forwardings: 0 local, 0 remote  
debug3: mux\_client\_request\_session: entering  
debug3: mux\_client\_request\_alive: entering  
debug3: mux\_client\_request\_alive: done pid = 24845  
debug3: mux\_client\_request\_session: session request sent  
debug1: mux\_client\_request\_session: master session id: 2  
debug3: mux\_client\_read\_packet: read header failed: Broken pipe  
debug2: Received exit status from master 0  
Shared connection to 54._XX.XX.XX_ closed.

Looking at the docker log file on the ec2 instance, the only obvious error I always see is something like:

[f648bc68] -job log(start, aab655401a74e9e6bb098c1d62d31e44beb1c116eb530296f315392a82c2e3dc, 4d76087678ee) = OK (0)  
**[error] attach.go:186 attach: stdout: write unix @: broken pipe**  
[error] attach.go:258 attach: job 1 returned error write unix @: broken pipe, aborting all jobs  
write unix @: broken pipe  
[f648bc68] -job build() = ERR (1)

I subsequently bumped up the timeout value thinking that the ssh client was timing out:

- name: Build the docker Nginx image  
docker\_image:  
**timeout: 1200**  
path: “{{ docker\_nginx\_dir }}”  
state: build  
name: “grid/nginx”

But it fails much before this timeout. So I added a retry condition:

- name: Build the docker Nginx image  
docker\_image:  
timeout: 1200  
path: “{{ docker\_nginx\_dir }}”  
state: build  
name: “grid/nginx”  
**register: build\_image\_result**  
**until: not build\_image\_result|failed**  
**retries: 2**  
**delay: 30**

This seems to consistently work - and I see that it always gets called twice - but I’m concerned as to why it would always need to. Any ideas?

Thanks!

More info if anyone needs it:  
**EC2 setup**

- name: Setup AWS EC2 Instances - US-West-1  
ec2:  
instance\_type: t2.micro  
image: “ami-41a7ea71”  
monitoring: no  
wait: yes  
group: microserver\_security\_group  
key\_name: _mykey_  
instance\_tags:  
Name: “MicroServer”  
count: 1  
region: “us-west-2”  
register: ec2west2

Docker install tasks:

- name: Update packages on the Amazon AMI  
yum: name=\* state=latest  
when: ansible\_distribution == ‘Amazon’

- name: Install or Update Python on the Amazon AMI  
yum: name=python state=latest  
when: ansible\_distribution == ‘Amazon’

- name: Install or Update Python-pip on the Amazon AMI  
yum: name=python-pip state=latest  
when: ansible\_distribution == ‘Amazon’

- name: Install or Update Docker on the Amazon AMI  
yum: name=docker state=latest  
when: ansible\_distribution == ‘Amazon’

- name: Install or Update docker-py on all docker hosts  
pip: name=docker-py version=0.3.1

# Had to delete /tmp/pip-build-root because pip would keep installing docker-py 0.5.3 as it was cached in this directory

- name: Start the docker service on the Amazon AMI  
service: name=docker state=restarted

# Trying restarted because it always seems to fail the first time around

when: ansible\_distribution == ‘Amazon’

Cheers.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 30, 2014, 9:46pm UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650/2 "2014-10-30T21:46:01Z")

</div>

Can you share the versions of Ansible, docker, and docker libraries you are using for starters?

---

<div class="post-metadata">

**Author:** ![Ananda\_Debnath](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Ananda\_Debnath](https://forum.ansible.com/u/Ananda_Debnath)\
**Post date:** [October 31, 2014, 3:17am UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650/3 "2014-10-31T03:17:30Z")

</div>

Thanks for responding Michael. Here’s all the version info:

Ansible 1.66 on an Ubuntu 13.10 EC2 host (below)

Ansible host info:  
$ ansible --version  
ansible 1.6.6

$ cat /etc/\*{release,version}  
DISTRIB\_ID=Ubuntu  
DISTRIB\_RELEASE=13.10  
DISTRIB\_CODENAME=saucy  
DISTRIB\_DESCRIPTION=“Ubuntu 13.10”  
NAME=“Ubuntu”  
VERSION=“13.10, Saucy Salamander”  
ID=ubuntu  
ID\_LIKE=debian  
PRETTY\_NAME=“Ubuntu 13.10”  
VERSION\_ID=“13.10”  
HOME\_URL=“[http://www.ubuntu.com/](http://www.ubuntu.com/)”  
SUPPORT\_URL=“[http://help.ubuntu.com/](http://help.ubuntu.com/)”  
BUG\_REPORT\_URL=“[http://bugs.launchpad.net/ubuntu/](http://bugs.launchpad.net/ubuntu/)”  
wheezy/sid  
Ubuntu 13.10 (Saucy Salamander)

Docker info  
$ docker version  
Client version: 1.2.0  
Client API version: 1.14  
Go version (client): go1.3.3  
Git commit (client): fa7b24f/1.2.0  
OS/Arch (client): linux/amd64

Python info:  
$ python --version  
Python 2.6.9  
$ pip --version  
pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)  
$ pip list  
argparse (1.2.1)  
aws-cfn-bootstrap (1.4)  
awscli (1.5.4)  
backports.ssl-match-hostname (3.4.0.2)  
bcdoc (0.12.2)  
boto (2.34.0)  
botocore (0.68.0)  
chardet (2.0.1)  
Cheetah (2.4.1)  
cloud-init (0.7.2)  
colorama (0.2.5)  
configobj (4.7.2)  
docker-py (0.3.1)  
docutils (0.11)  
iniparse (0.3.1)  
jmespath (0.4.1)  
kitchen (1.1.1)  
lockfile (0.8)  
Markdown (2.4.1)  
ordereddict (1.1)  
paramiko (1.7.5)  
PIL (1.1.6)  
ply (3.4)  
pycrypto (2.6.1)  
pycurl (7.19.0)  
Pygments (1.4)  
pygpgme (0.1)  
pyliblzma (0.5.3)  
pystache (0.5.3)  
python-daemon (1.5.2)  
python-dateutil (2.1)  
pyxattr (0.5.0)  
PyYAML (3.10)  
requests (2.2.1)  
rsa (3.1.2)  
simplejson (3.5.3)  
six (1.3.0)  
urlgrabber (3.9.1)  
urllib3 (1.8.2)  
websocket-client (0.11.0)  
yum-metadata-parser (1.1.4)

---

<div class="post-metadata">

**Author:** ![Ananda\_Debnath](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Ananda\_Debnath](https://forum.ansible.com/u/Ananda_Debnath)\
**Post date:** [October 31, 2014, 9:43pm UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650/4 "2014-10-31T21:43:19Z")

</div>

Any ideas?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [November 1, 2014, 2:51pm UTC](https://forum.ansible.com/t/consistent-docker-image-module-failure-on-ec2-instances/16650/5 "2014-11-01T14:51:18Z")

</div>

Please check on the latest version of Ansible – preferably the development branch since this is Docker and changing extremely quickly - and let us know if you still encounter problems.
