ansible does not provide high level modules to manage 'packages' but has
distro specific modules, like yup and apt.
If you manage different distro's, you could write a specific playbook per
distro, handling the differences you mention.
Then you target those playbooks to only the hosts runing that specific
distro after you created dynamic groups based on the distro name with the
group_by module.
Serge