<h5 dir="auto">Issue Type:</h5>
<p dir="auto">“Docs Pull Request”.</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.7</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Centos 6.5</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Running module mysql_db with state of import and with a missing database name on mysql return connection error message.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">The following test</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: test state import for a database name with target and missing database
  mysql_db: name=datadump state=import target=/tmp/datadump.sql.bz2
  register: result
  ignore_errors: true"><pre class="notranslate"><code class="notranslate">- name: test state import for a database name with target and missing database
  mysql_db: name=datadump state=import target=/tmp/datadump.sql.bz2
  register: result
  ignore_errors: true
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Perhaps tell the user that the database name does not exist on mysql</p>
<p dir="auto"><code class="notranslate">result</code> return the following message:  <code class="notranslate">msg: database name that you are trying to import does not exist</code></p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto"><code class="notranslate">result</code> return the following message:  <code class="notranslate">msg: unable to connect, check login_user and login_password are correct, or alternatively check ~/.my.cnf contains credentials</code></p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/velotraveler/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/velotraveler">@velotraveler</a> on 2016-11-11T01:14:16Z</p>

<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">iptables</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">from OS: Red Hat Enterprise Linux Server release 6.6 (Santiago) / iptables 1.4.7<br>
managed OS (2 hosts):</p>
<ul dir="auto">
<li>Red Hat Enterprise Linux Server release 5.8 (Tikanga) / iptables 1.3.5</li>
<li>Red Hat Enterprise Linux Server release 6.6 (Santiago) / iptables 1.4.7</li>
</ul>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">iptables module installs duplicate rules with every run. It looks like module uses "iptables -C" to check whether rule already exists, but that option does not exist in older versions of iptables (such as 1.3.5) and although it exists in iptables 1.4.7 it does not seem to be working.  Suggest switching to a different method of verification, such as parsing the output of "iptables-save" or "iptables -L" (although that might introduce difficulties as module inputs might not match command-line output, such as with symbolic ICMP types or IPs/ports specified by name vs. by number).</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Create an iptables rule on a host where iptables does not support the -C option, or where it isn't supported the way this module expects it, such as iptables 1.4.7.<br>
Then run the playbook again, the module will not recognize the old rules exist and it will install duplicate copies of all rules.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="iptables: table=filter chain=OUTPUT jump=DROP action=insert protocol=icmp icmp_type=destination-unreachable"><pre class="notranslate"><code class="notranslate">iptables: table=filter chain=OUTPUT jump=DROP action=insert protocol=icmp icmp_type=destination-unreachable
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">only one copy of rule no matter how many times I run the playbook</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">multiple copies of rules, one for each time I ran the playbook</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  anywhere             anywhere            icmp destination-unreachable 
DROP       icmp --  anywhere             anywhere            icmp destination-unreachable "><pre class="notranslate"><code class="notranslate"># iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  anywhere             anywhere            icmp destination-unreachable 
DROP       icmp --  anywhere             anywhere            icmp destination-unreachable 
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="188661965" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-extras/issues/3428" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-extras/issues/3428/hovercard" href="https://github.com/ansible/ansible-modules-extras/issues/3428">ansible/ansible-modules-extras#3428</a></p>