A long time ago, I remember reading that Ansible makes simple things hard and hard things simple. This kind of reminds me of that
Modules are great for reducing the maintenance burden on you/your team and providing an easy interface for more complicated checks. When a module doesnt meet your needs, you have two options:
Write a new module or open a PR to update an existing module
Use the shell/command module
I think your approach is great, given the constraints you’ve found. There is one change I would suggest though. I would use the shell module to get the list of packages, and then pass that into the apt module. That way, you get the best of both worlds. Something like this (I didnt test it):