need playbook to update ubuntu and centos

how can i update both ubuntu and centos boxes all in one playbook?

How do you perform that currently?

I suggest taking a look at the service module
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html
You can use this module to update both YUM and APT packages.

Some packages have different names, so be sure to take that into account.
You can see an example here:
https://youtu.be/CYghlf-6Opc?t=929

You can simply plagiarize the Ansible docs for yum to upgrade

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html

and apt to upgrade

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html

however this is all dependent on your requirements, I use a precheck, upgrade, changelog collection of playbooks with host logic for the Linux hosts I currently maintain, depends on your estate.

this is all i have for ubuntu system. please advise

this is all i have for ubuntu system. please advise

What advice are you looking for?

advice. Need to add the yum part for centos

need some examples

also i want to know how to break this into a role instead

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/yum_module.html#examples

https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html