Managing Podman containers: Systemd or Ansible?

I have RHEL 9.2 installed on my Raspberry Pi 4 Mode B, on which, I am running some of my personal web services like Nextcloud, Gitea and more; taking advantage of containers. I don’t know how much useful this information is, but please note that all of my containers are rootless.

This setup was achieved with the following steps:

  1. Create a compose file and use podman-compose to initially create the containers I need.
  2. Create a Systemd unit file for each container using podman generate systemd.
  3. Stop and remove all the current containers that were generated using podman-compose.
  4. Enable the generated Systemd unit files created on Step 2.

With that done, I am now managing all of my Podman containers using Systemd. I see no problems with the current setup. Containers, when fail, for whatever reason, are restarted immediately by Systemd. Just to re-iterate, the current setup works for me and I have no issues with it.

However, I am looking to move (clean install) to Rocky Linux (for reasons I will not dive into in this post) and thought that “Hmm, since I will be setting it up from scratch, let’s try Ansible. I’ve heard a lot about it.”

So I installed Rocky Linux on a spare Raspberry Pi I had lying around. Most of the tasks that I perform on a fresh install, I now have an Ansible playbook for those. One, from the remaining tasks to automate is, the initial setup creating Podman containers. I want to create Podman containers using Ansible now, the sole reason being that 85% of things are already handled by Ansible, so why not containers too? (Again, I don’t have a reason to migrate off the current setup, I’m just exploring my options.)

I haven’t look that deeply into managing Podman containers via Ansible, but from what I see, only creation and destruction (along with pulling and pushing images) is possible. Yes, Ansible can make sure that the containers are running, but that is only when you run your playbook(s), not like Systemd where it will automatically restart your failed container.

One middle ground I have in mind is to replace podman-compose’s job with Ansible and also use Ansible to create services for each container (if they don’t already exist). And then use Ansible to make sure that those services are enabled and/or active

So, I’m looking for feedback and hearing from others about how they manage their Podman containers using Ansible. What are the things that you like about the Ansible approach (specifically for container management)? I’d also like to know what are the pain points with that approach, if any.

Thank you in advance for taking the time to read and replying!

I haven’t setup a role yet for deploying the containers I use but if I were to do it I would probably use the different Ansible collection container modules.
There is a module for systemd in there do which I would then user to generate a user systemd-unit-file, so that way you could deploy your containers by using Ansible and have systemd be in control of them once they are deployed.