---

  - name: Clean up yum cache
    command: dnf clean all

  - name: Really clean yum cache
    shell: for i in `ls /var/lib/dnf/`; do rm -rfv /var/lib/dnf/${i}/*; done

  - name: Determine kernel version in chroot
    shell: ls /lib/modules/
    register: kernel_version

  - name: Generate module dependencies with depmod for kernel
    shell: depmod -a {{ kernel_version.stdout }}

  - name: Regenerate initramfs using dracut
    shell: dracut --force --regenerate-all

  - name: Apply default SELinux contexts to the system
    shell: restorecon -R /
    when: selinux_enabled

---

  - name: Clean up yum cache
    command: "{{ ansible_pkg_mgr }} clean all"

  - name: Really clean yum cache
    shell: for i in `ls /var/lib/{{ ansible_pkg_mgr }}/`; do rm -rfv /var/lib/{{ ansible_pkg_mgr }}/${i}/*; done

  - name: Determine kernel version in chroot
    shell: ls /lib/modules/
    register: kernel_version

  - name: Generate module dependencies with depmod for kernel
    shell: depmod -a {{ kernel_version.stdout }}

  - name: Regenerate initramfs using dracut
    shell: dracut --force --regenerate-all

  - name: Apply default SELinux contexts to the system
    shell: restorecon -R /
    when: selinux_enabled

Swap out ansible_pkg_mgr for dnf
Swap out ansible_pkg_mgr for dnf
