How to best manage several containers in ansible

I have a home server where I run 15+ containers. Some use common databases and some write to volumes. I have some tasks that need to be run before some of the containers and some tasks used to pull configuration from the server to the ansible controller.

How do I best arrange all of these containers in ansible? Right now I have every container in its own role, but that leads to a lot of code duplication.

I have looked into compose, but as I need to run task before some containers start, it does not seem like a good fit.

Another idea is to try and write a role for all containers that then creates containers based on a config file, but that seem like recreating docker compose with some small extensions.

Any best practise here or suggestions and experience?

The podman team and the linux-system-roles team have developed a podman role https://github.com/linux-system-roles/podman/ - you describe your containers/pods using the kubernetes yaml format and the role manages them for you. Requires podman 4.2 or later. The role also manages the various podman configuration files. If you need more lower level container management, there is the containers.podman collection of modules.