<p dir="auto">As discussed in <a href="https://groups.google.com/forum/#!topic/ansible-project/9s8ARNfKQyU" rel="nofollow">Google Groups</a></p>
<p dir="auto">I have a task that imports a db file into mysql but it fails the second time I re-run the playbook.</p>
<p dir="auto">In order to overcome the failure I need to login to the mysql server and drop the database in order to import successfully in the second play, this is not possible in a production environment and doesn't make my code idempotent. Using the ignore_errors I still get the same problem causing Ansible to stop the execution on the next play and exit .</p>
<h3 dir="auto">Task :</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    - name: import DB
      mysql_db: login_host={{ DB_ADDRESS }} login_user={{ DB_MASTER_USERNAME }} login_password={{ DB_MASTER_PASSWORD }} name=mmdb state=import target=roles/mmdb/templates/mmdb-init-tables.sql.j2
      ignore_errors: yes"><pre class="notranslate"><code class="notranslate">    - name: import DB
      mysql_db: login_host={{ DB_ADDRESS }} login_user={{ DB_MASTER_USERNAME }} login_password={{ DB_MASTER_PASSWORD }} name=mmdb state=import target=roles/mmdb/templates/mmdb-init-tables.sql.j2
      ignore_errors: yes
</code></pre></div>
<h3 dir="auto">Error message</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed: [localhost] =&gt; {&quot;failed&quot;: true}
msg: ERROR 1062 (23000) at line 4: Duplicate entry 'CM' for key 'PRIMARY'"><pre class="notranslate"><code class="notranslate">failed: [localhost] =&gt; {"failed": true}
msg: ERROR 1062 (23000) at line 4: Duplicate entry 'CM' for key 'PRIMARY'
</code></pre></div>
<h3 dir="auto">Ansible version</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 1.4 (devel 6008ea40ee) last updated 2013/11/12 12:34:58 (GMT +000)"><pre class="notranslate"><code class="notranslate">ansible 1.4 (devel 6008ea40ee) last updated 2013/11/12 12:34:58 (GMT +000)
</code></pre></div>
<p dir="auto">In other tasks the "ignore_errors: yes" works just fine but that doesn't seem to be the case for an import failure using the mysql_db module.</p>
<h2 dir="auto">Bug Description:</h2>
<p dir="auto">Simple ansible-playbook indefinitely hangs when using su. This can be repeated indefinitely.</p>
<h2 dir="auto">Version affected:</h2>
<ul dir="auto">
<li>ansible 1.9.1</li>
<li>ansible 1.9.2</li>
</ul>
<h2 dir="auto">Version not affected (using the same script):</h2>
<ul dir="auto">
<li>ansible 1.6.10</li>
</ul>
<h2 dir="auto">Environment tested on</h2>
<ul dir="auto">
<li>Linux Redhat/Centos</li>
<li>Python version: 2.6.6</li>
</ul>
<h2 dir="auto">Other details:</h2>
<ul dir="auto">
<li>The playbook is working fine if su is not used. Root credential is correct.</li>
<li>Using the ping module with su works fine.</li>
<li>The password prompt is "Password:" (without the quotes)</li>
</ul>
<h2 dir="auto">Run details</h2>
<h3 dir="auto">Playbook</h3>
<h4 dir="auto">Main file:</h4>
<ul dir="auto">
<li>
<p dir="auto">name: Install app on my servers<br>
hosts: my_hosts<br>
gather_facts: no<br>
remote_user: my_user<br>
su: yes</p>
<p dir="auto">roles:</p>
<ul dir="auto">
<li>app_install</li>
</ul>
</li>
</ul>
<h4 dir="auto">app_install role (under tasks/main.yml)</h4>
<ul dir="auto">
<li>name: query whoami<br>
shell: whoami</li>
</ul>
<h3 dir="auto">Log</h3>
<blockquote>
<p dir="auto">[PROJECT] myotheruser@myprodserver# ansible-playbook -i hosts -k --ask-su-pass my_playbook.yml -vvvv<br>
SSH password:<br>
SU password[defaults to SSH password]:</p>
<p dir="auto">PLAY [Install app on my servers] ************************************</p>
<p dir="auto">TASK: [app_install | query whoami] ***<br>
&lt;my_server.mydomain.com&gt; ESTABLISH CONNECTION FOR USER: my_user on PORT 22 TO my_server.mydomain.com<br>
&lt;my_server.mydomain.com&gt; REMOTE_MODULE command whoami #USE_SHELL<br>
&lt;my_server.mydomain.com&gt; EXEC /bin/sh -c 'mkdir -p /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733 &amp;&amp; chmod a+rx /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733 &amp;&amp; echo /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733'<br>
&lt;my_server.mydomain.com&gt; PUT /tmp/tmp6UGeFE TO /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733/command<br>
&lt;my_server.mydomain.com&gt; EXEC /bin/sh -c 'su root -c "/bin/sh -c '"'"'echo BECOME-SUCCESS-xzmbgooensxgrlbezhnlngbagojwbczg; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733/command; rm -rf /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733/ &gt;/dev/null 2&gt;&amp;1'"'"'"'</p>
</blockquote>
<h3 dir="auto">Extra tests</h3>
<p dir="auto">I have run the command below on the remote server. It is presenting the "Password:" prompt and execute correctly the command.</p>
<blockquote>
<p dir="auto">/bin/sh -c 'su root -c "/bin/sh -c '"'"'echo BECOME-SUCCESS-xzmbgooensxgrlbezhnlngbagojwbczg; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733/command; rm -rf /tmp/.ansible_my_user/tmp/ansible-tmp-1438014075.95-221459817104733/ &gt;/dev/null 2&gt;&amp;1'"'"'"</p>
</blockquote>
<h2 dir="auto">Happy to do any other test if needed</h2>