<p dir="auto">This code in the file module causes problems in the check mode:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    if prev_state != 'absent' and state == 'absent':
        try:
            if prev_state == 'directory':
                if os.path.islink(path):
                    if module.check_mode:
                        module.exit_json(changed=True)
                    os.unlink(path)
                else:
                    try:
                        if module.check_mode:
                            module.exit_json(changed=True)
                        shutil.rmtree(path, ignore_errors=False)
                    except:
                        module.exit_json(msg=&quot;rmtree failed&quot;)
            else:
                if module.check_mode:
                    module.exit_json(changed=True)
                os.unlink(path)
        except Exception, e:
            module.fail_json(path=path, msg=str(e))
        module.exit_json(path=path, changed=True)"><pre class="notranslate"><code class="notranslate">    if prev_state != 'absent' and state == 'absent':
        try:
            if prev_state == 'directory':
                if os.path.islink(path):
                    if module.check_mode:
                        module.exit_json(changed=True)
                    os.unlink(path)
                else:
                    try:
                        if module.check_mode:
                            module.exit_json(changed=True)
                        shutil.rmtree(path, ignore_errors=False)
                    except:
                        module.exit_json(msg="rmtree failed")
            else:
                if module.check_mode:
                    module.exit_json(changed=True)
                os.unlink(path)
        except Exception, e:
            module.fail_json(path=path, msg=str(e))
        module.exit_json(path=path, changed=True)
</code></pre></div>
<p dir="auto">The line <code class="notranslate">module.exit_json(changed=True)</code> raises <code class="notranslate">SystemExit</code>, but there are two <code class="notranslate">except</code> lines that catch it and report it as error. However at that point, the first JSON was already printed, so there are two JSONs in the response.</p>
<p dir="auto">I can send a patch to fix this if you want, but I think the best solution would be to remove the large and generic <code class="notranslate">try</code>/<code class="notranslate">except</code>.</p>
<p dir="auto"><strong>How to reproduce:</strong><br>
First create a directory on some random host:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible test-host -i ansible.hosts -m file -a 'path=/tmp/randompath state=directory'
mymachine.domain.se | success &gt;&gt; {
    &quot;changed&quot;: true, 
    &quot;gid&quot;: 1007, 
    &quot;group&quot;: &quot;jens&quot;, 
    &quot;mode&quot;: &quot;0755&quot;, 
    &quot;owner&quot;: &quot;jens&quot;, 
    &quot;path&quot;: &quot;/tmp/randompath&quot;, 
    &quot;size&quot;: 4096, 
    &quot;state&quot;: &quot;directory&quot;, 
    &quot;uid&quot;: 1007
}"><pre class="notranslate">$ ansible test-host -i ansible.hosts -m file -a <span class="pl-s"><span class="pl-pds">'</span>path=/tmp/randompath state=directory<span class="pl-pds">'</span></span>
mymachine.domain.se <span class="pl-k">|</span> success <span class="pl-k">&gt;&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>changed<span class="pl-pds">"</span></span>: true, 
    <span class="pl-s"><span class="pl-pds">"</span>gid<span class="pl-pds">"</span></span>: 1007, 
    <span class="pl-s"><span class="pl-pds">"</span>group<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>jens<span class="pl-pds">"</span></span>, 
    <span class="pl-s"><span class="pl-pds">"</span>mode<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>0755<span class="pl-pds">"</span></span>, 
    <span class="pl-s"><span class="pl-pds">"</span>owner<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>jens<span class="pl-pds">"</span></span>, 
    <span class="pl-s"><span class="pl-pds">"</span>path<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>/tmp/randompath<span class="pl-pds">"</span></span>, 
    <span class="pl-s"><span class="pl-pds">"</span>size<span class="pl-pds">"</span></span>: 4096, 
    <span class="pl-s"><span class="pl-pds">"</span>state<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>directory<span class="pl-pds">"</span></span>, 
    <span class="pl-s"><span class="pl-pds">"</span>uid<span class="pl-pds">"</span></span>: 1007
}</pre></div>
<p dir="auto">Then check if the directory would have been deleted (note <code class="notranslate">--check</code>):</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible test-host -i ansible.hosts --check -m file -a 'path=/tmp/randompath state=absent'
mymachine.domain.se | FAILED =&gt; failed to parse: {&quot;changed&quot;: true}
{&quot;msg&quot;: &quot;rmtree failed&quot;, &quot;changed&quot;: false}"><pre class="notranslate">$ ansible test-host -i ansible.hosts --check -m file -a <span class="pl-s"><span class="pl-pds">'</span>path=/tmp/randompath state=absent<span class="pl-pds">'</span></span>
mymachine.domain.se <span class="pl-k">|</span> FAILED =<span class="pl-k">&gt;</span> failed to parse: {<span class="pl-s"><span class="pl-pds">"</span>changed<span class="pl-pds">"</span></span>: true}
{<span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>rmtree failed<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>changed<span class="pl-pds">"</span></span>: false}</pre></div>
<p dir="auto"><strong>Expected output:</strong></p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible test-host -i ansible.hosts --check -m file -a 'path=/tmp/randompath state=absent'

mymachine.domain.se | success &gt;&gt; {
    &quot;changed&quot;: true
}"><pre class="notranslate">$ ansible test-host -i ansible.hosts --check -m file -a <span class="pl-s"><span class="pl-pds">'</span>path=/tmp/randompath state=absent<span class="pl-pds">'</span></span>

mymachine.domain.se <span class="pl-k">|</span> success <span class="pl-k">&gt;&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>changed<span class="pl-pds">"</span></span>: <span class="pl-c1">true</span>
}</pre></div>
<p dir="auto">I have pull request for this that I'll submit separately.</p>