handling specific scenarios in package module

Hi all,

I am using package module to install packages in the system. But I need to handle a specific case for example some ubuntu kernel requires some specific command to be run for installing the package.

https://docs.ansible.com/ansible/2.5/modules/package_module.html

I want to store the package module output to a variable and check whether specific strings appear in stdout and handle that specific case. Can anyone help how can I achieve this ?
Any code snippet will help.

Regards
Pradeep

That is what the `register` keyword is for
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#registering-variables