Issue 1:
Issue Type:

Bug Report

Ansible Version:

ansible 1.7

specificaly, git commit 6fdf77f

Environment:

Running from Mac OS X. Ansible installed in virtualenv.

$ pip freeze
Jinja2==2.7.3
MarkupSafe==0.23
PyYAML==3.11
ansible==1.7
ecdsa==0.11
paramiko==1.14.0
pycrypto==2.6.1
wsgiref==0.1.2

Managing: ubuntu-14.04 via vagrant.

Summary:

Ansible hangs on docker_image building when the image already exists. The whole playground is at https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken branch (pretty simple).

Specifically, this task causes the problem (playbook.xml, line 97):

- name: Build or re-build an image.
sudo: yes
#FIXME: Hangs on recv() somewhere inside docker-py (if the image exists?).
docker_image: name=mycont path=Docker.dir state=build
#shell: docker build -t mycont ~{{ansible_ssh_user}}/Docker.dir

Command-line approach (i.e. not through docker-py) works fine.

Steps To Reproduce:

To reproduce:

vagrant up — it works fine for the first time (provision implied).

vagrant provision — hangs on this task.

If you log into, remove the image (mycont), then provision it again, it works for the first time, and hangs for the second time. This is why my assumption is it hangs when the image already exists.

vagrant ssh

docker kill timer_from_image && docker rm timer_from_image

docker rmi mycont

exit

vagrant provision — first time is ok

vagrant provision — second time it hangs or shows an "unknown error"

If launched by hand from inside, and then interrupted with Ctrl+C (after it hangs), the stackdump is a follows:

ANSIBLE_KEEP_REMOTE_FILES=1 vagrant provision

Wait till it hags, Ctrl+C, copy-paste the last command.

vagrant ssh

/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image

Wait 5-10 secs, Ctrl+C

vagrant@vagrant-ubuntu-trusty-64:~$ /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image
^CTraceback (most recent call last):
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 1554, in <module>
main()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 234, in main
image_id = manager.build()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 144, in build
for chunk in stream:
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 229, in _stream_helper
size_line = socket.readline()
KeyboardInterrupt

Expected Results:

It does not hang.

Actual Results:

It hangs.

Issue 2:
Ansible hangs on docker_image building when the image already exists. The whole playground is at https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken branch (pretty simple).

Specifically, this task causes the problem (playbook.xml, line 97):

- name: Build or re-build an image.
sudo: yes
#FIXME: Hangs on recv() somewhere inside docker-py (if the image exists?).
docker_image: name=mycont path=Docker.dir state=build
#shell: docker build -t mycont ~{{ansible_ssh_user}}/Docker.dir

To reproduce:

vagrant up — it works fine for the first time (provision implied).

vagrant provision — hangs on this task.

If you log into, remove the image (mycont), then provision it again, it works for the first time, and hangs for the second time. This is why my assumption is it hangs when the image already exists.

vagrant ssh

docker kill timer_from_image && docker rm timer_from_image

docker rmi mycont

exit

vagrant provision — first time is ok

vagrant provision — second time it hangs or shows an "unknown error"

If launched by hand from inside, and then interrupted with Ctrl+C (after it hangs), the stackdump is a follows:

ANSIBLE_KEEP_REMOTE_FILES=1 vagrant provision

Wait till it hags, Ctrl+C, copy-paste the last command.

vagrant ssh

/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image

Wait 5-10 secs, Ctrl+C

vagrant@vagrant-ubuntu-trusty-64:~$ /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image
^CTraceback (most recent call last):
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 1554, in <module>
main()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 234, in main
image_id = manager.build()
File "/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image", line 144, in build
for chunk in stream:
File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 229, in _stream_helper
size_line = socket.readline()
KeyboardInterrupt

Command-line approach (i.e. not through docker-py) works fine.