<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.7<br>
specificaly, git commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/6fdf77f9fedd741deda08a2cbc51412155b4d6c5/hovercard" href="https://github.com/ansible/ansible/commit/6fdf77f9fedd741deda08a2cbc51412155b4d6c5"><tt>6fdf77f</tt></a></p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Running from Mac OS X. Ansible installed in virtualenv.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ 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"><pre class="notranslate"><code class="notranslate">$ 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
</code></pre></div>
<p dir="auto">Managing: ubuntu-14.04 via vagrant.</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Ansible hangs on docker_image building when the image already exists. The whole playground is at <a href="https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken">https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken</a> branch (pretty simple).</p>
<p dir="auto">Specifically, this task causes the problem (playbook.xml, line 97):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    - 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"><pre class="notranslate"><code class="notranslate">    - 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
</code></pre></div>
<p dir="auto">Command-line approach (i.e. not through docker-py) works fine.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">To reproduce:</p>
<ol dir="auto">
<li>vagrant up — it works fine for the first time (provision implied).</li>
<li>vagrant provision — hangs on this task.</li>
</ol>
<p dir="auto">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.</p>
<ol dir="auto">
<li>vagrant ssh</li>
<li>docker kill timer_from_image &amp;&amp; docker rm timer_from_image</li>
<li>docker rmi mycont</li>
<li>exit</li>
<li>vagrant provision — first time is ok</li>
<li>vagrant provision — second time it hangs or shows an "unknown error"</li>
</ol>
<p dir="auto">If launched by hand from inside, and then interrupted with Ctrl+C (after it hangs), the stackdump is a follows:</p>
<ol dir="auto">
<li>ANSIBLE_KEEP_REMOTE_FILES=1 vagrant provision</li>
<li>Wait till it hags, Ctrl+C, copy-paste the last command.</li>
<li>vagrant ssh</li>
<li>/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image</li>
<li>Wait 5-10 secs, Ctrl+C</li>
</ol>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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 &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 1554, in &lt;module&gt;
    main()
  File &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 234, in main
    image_id = manager.build()
  File &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 144, in build
    for chunk in stream:
  File &quot;/usr/local/lib/python2.7/dist-packages/docker/client.py&quot;, line 229, in _stream_helper
    size_line = socket.readline()
KeyboardInterrupt"><pre class="notranslate">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 <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">1554</span>, in <span class="pl-en">&lt;module&gt;</span>
    main()
  File <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">234</span>, in <span class="pl-en">main</span>
    image_id <span class="pl-k">=</span> manager.build()
  File <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">144</span>, in <span class="pl-en">build</span>
    <span class="pl-k">for</span> chunk <span class="pl-k">in</span> stream:
  File <span class="pl-s">"/usr/local/lib/python2.7/dist-packages/docker/client.py"</span>, line <span class="pl-c1">229</span>, in <span class="pl-en">_stream_helper</span>
    size_line <span class="pl-k">=</span> socket.readline()
KeyboardInterrupt</pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">It does not hang.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">It hangs.</p>
<p dir="auto">Ansible hangs on docker_image building when the image already exists. The whole playground is at <a href="https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken">https://github.com/nolar/vagrant-ansible-docker-sample/tree/docker_image_broken</a> branch (pretty simple).</p>
<p dir="auto">Specifically, this task causes the problem (playbook.xml, line 97):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    - 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"><pre class="notranslate"><code class="notranslate">    - 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
</code></pre></div>
<p dir="auto">To reproduce:</p>
<ol dir="auto">
<li>vagrant up — it works fine for the first time (provision implied).</li>
<li>vagrant provision — hangs on this task.</li>
</ol>
<p dir="auto">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.</p>
<ol dir="auto">
<li>vagrant ssh</li>
<li>docker kill timer_from_image &amp;&amp; docker rm timer_from_image</li>
<li>docker rmi mycont</li>
<li>exit</li>
<li>vagrant provision — first time is ok</li>
<li>vagrant provision — second time it hangs or shows an "unknown error"</li>
</ol>
<p dir="auto">If launched by hand from inside, and then interrupted with Ctrl+C (after it hangs), the stackdump is a follows:</p>
<ol dir="auto">
<li>ANSIBLE_KEEP_REMOTE_FILES=1 vagrant provision</li>
<li>Wait till it hags, Ctrl+C, copy-paste the last command.</li>
<li>vagrant ssh</li>
<li>/usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image</li>
<li>Wait 5-10 secs, Ctrl+C</li>
</ol>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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 &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 1554, in &lt;module&gt;
    main()
  File &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 234, in main
    image_id = manager.build()
  File &quot;/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image&quot;, line 144, in build
    for chunk in stream:
  File &quot;/usr/local/lib/python2.7/dist-packages/docker/client.py&quot;, line 229, in _stream_helper
    size_line = socket.readline()
KeyboardInterrupt"><pre class="notranslate">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 <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">1554</span>, in <span class="pl-en">&lt;module&gt;</span>
    main()
  File <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">234</span>, in <span class="pl-en">main</span>
    image_id <span class="pl-k">=</span> manager.build()
  File <span class="pl-s">"/home/vagrant/.ansible/tmp/ansible-tmp-1403972347.56-120405055892302/docker_image"</span>, line <span class="pl-c1">144</span>, in <span class="pl-en">build</span>
    <span class="pl-k">for</span> chunk <span class="pl-k">in</span> stream:
  File <span class="pl-s">"/usr/local/lib/python2.7/dist-packages/docker/client.py"</span>, line <span class="pl-c1">229</span>, in <span class="pl-en">_stream_helper</span>
    size_line <span class="pl-k">=</span> socket.readline()
KeyboardInterrupt</pre></div>
<p dir="auto">Command-line approach (i.e. not through docker-py) works fine.</p>