title: Ansible dnf module returns success even when dnf fails
body: <ol>
  <li>This is the initial state of my system:</li>
  </ol>
  <ul>
  <li>I have myrpm-2.0 installed.</li>
  <li>This rpm creates just a file.</li>
  <li><code>/usr/share/myfile</code> exists as a file.</li>
  </ul>
  <pre><code>    /root# rpm -q myrpm
      myrpm-2.0-0.x86_64
      /root# rpm -ql myrpm-2.0-0.x86_64
      /usr/share
      /usr/share/myfile
      /root# ls -lrt /usr/share | grep myfile
      -rw-r--r--   1 root root     11 May 25 17:32 myfile
      /root#
  </code></pre>
  <ol start="2">
  <li>Now I am simulating an error condition. I manually removed the file and created a directory in it's place.</li>
  </ol>
  <pre><code>    /root# ls -lrt /usr/share | grep myfile
      drwxr-xr-x   2 root root   4096 May 25 18:33 myfile
      /root#
  </code></pre>
  <ol start="3">
  <li>I prepared a higher  version 3.0 of the same rpm, which copies the same file.</li>
  </ol>
  <pre><code>    /root# rpm -ql /root/update/myrpm-3.0-0.x86_64.rpm
      /usr/share
      /usr/share/myfile
      /root#
  </code></pre>
  <p>4-Test-1: Trying rpm upgrade using ansible's builtin dnf module.
  Following is my playbook:</p>
  <pre><code>/root# cat test.yaml
  ---
  - hosts: localhost
    tasks:
      - name: update rpm
        dnf:
          name: &quot;myrpm&quot;
          state: latest
  /root#
  </code></pre>
  <p>Executing this playbook gives return code as 0.</p>
  <pre><code>/root# ansible-playbook -vvv test.yaml
  ...
  changed: [localhost] =&gt; {
      &quot;changed&quot;: true,
      &quot;invocation&quot;: {
          &quot;module_args&quot;: {
              &quot;allow_downgrade&quot;: false,
              &quot;autoremove&quot;: false,
              &quot;bugfix&quot;: false,
              &quot;conf_file&quot;: null,
              &quot;disable_excludes&quot;: null,
              &quot;disable_gpg_check&quot;: false,
              &quot;disable_plugin&quot;: [],
              &quot;disablerepo&quot;: [],
              &quot;download_dir&quot;: null,
              &quot;download_only&quot;: false,
              &quot;enable_plugin&quot;: [],
              &quot;enablerepo&quot;: [],
              &quot;exclude&quot;: [],
              &quot;install_repoquery&quot;: true,
              &quot;install_weak_deps&quot;: true,
              &quot;installroot&quot;: &quot;/&quot;,
              &quot;list&quot;: null,
              &quot;lock_timeout&quot;: 30,
              &quot;name&quot;: [
                  &quot;myrpm&quot;
              ],
              &quot;releasever&quot;: null,
              &quot;security&quot;: false,
              &quot;skip_broken&quot;: false,
              &quot;state&quot;: &quot;latest&quot;,
              &quot;update_cache&quot;: false,
              &quot;update_only&quot;: false,
              &quot;validate_certs&quot;: true
          }
      },
      &quot;msg&quot;: &quot;&quot;,
      &quot;rc&quot;: 0,
      &quot;results&quot;: [
          &quot;Installed: myrpm-3.0-0.x86_64&quot;,
          &quot;Removed: myrpm-2.0-0.x86_64&quot;
      ]
  }
  META: ran handlers
  META: ran handlers
  
  PLAY RECAP *******************************************************************************************
  localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  
  /root# echo $?
  0
  /root#
  </code></pre>
  <p>rc is 0 as per the verbose log.
  However, I can see that dnf command has failed.</p>
  <pre><code>/root# dnf history | head -n 3
  ID     | Command line             | Date and time    | Action(s)      | Altered
  -------------------------------------------------------------------------------
      27 |                          | 2022-05-25 18:39 | Upgrade        |    1 EE
  /root# dnf history info 27 | tail -6
  Packages Altered:
   ** Upgrade  myrpm-3.0-0.x86_64 @My_Update
      Upgraded myrpm-2.0-0.x86_64 @@System
  Scriptlet output:
     1 error: unpacking of archive failed on file /usr/share/myfile: cpio: File from package already exists as a directory in system
     2 error: myrpm-3.0-0.x86_64: install failed
  /root#
  </code></pre>
  <p>4-Test-2: I made my system in exact same state as 3, and used direct dnf command instead of playbook.</p>
  <pre><code>/root# dnf update myrpm
  ...
    Preparing        :                                                                              1/1
    Upgrading        : myrpm-3.0-0.x86_64                                                           1/2
  Error unpacking rpm package myrpm-3.0-0.x86_64
  error: unpacking of archive failed on file /usr/share/myfile: cpio: File from package already exists as a directory in system
  
    Cleanup          : myrpm-2.0-0.x86_64                                                           2/2
  error: myrpm-3.0-0.x86_64: install failed
  
    Verifying        : myrpm-3.0-0.x86_64                                                           1/2
    Verifying        : myrpm-2.0-0.x86_64                                                           2/2
  
  Failed:
    myrpm-3.0-0.x86_64
  
  Error: Transaction failed
  /root# echo $?
  1
  /root# 
  </code></pre>
  <p>Any clue on why the playbook did not show task as failed?</p>