LinuxBuz published two Ansible tutorials showing how to use the Ansible apt and yum modules.
Ansible apt Module - Tutorial and Examples
Ansible apt module is used to manage packages using the apt package manager on Debian based Linux distributions including, Ubuntu, Debian, etc.
Ansible apt Module - Tutorial and Examples - LinuxBuz
Ansible yum Module - Tutorial and Examples
Ansible yum module is used to manage packages using the yum package manager on CentOS and RHEL based Linux distributions including, RHEL, CentOS, Fedora, etc.
Ansible yum Module - Tutorial and Examples - LinuxBuz