Deploying Docker containers via Ansible, etc? reddit / selfhosted ---------------------------------------------------------------------- Vlinux · 2023-11-22 23:30 For those of you who deploy your docker/compose configs via Ansible/git/etc, how do you handle cases where you're just trying out a new container service or testing some changes to the configuration? Do you make the change, run it through your Ansible (or whatever) deployment process and see if it works, or make the change on the server and then replicate it to your "deployed" config once you've verified that it works? I currently have some configs deployed via Ansible, but my Docker Compose files are all individually managed (but centrally backed-up) on the individual servers. ---------------------------------------------------------------------- Anycast · 2023-11-23 00:01 I use ansible roles. Each docker compose file is a jinja2 template. I then use vars for hosts to change that docker compose file when I run the playbook. ---------------------------------------------------------------------- Vlinux · 2023-11-23 03:26 What about testing changes though? Do you make the change in your template, run the playbook, then ssh into the server to check if the container started up properly, then repeat if something didn't work right or if there was a syntax issue or something? ---------------------------------------------------------------------- themagixboy · 2023-11-23 12:03 I also use ansible roles, not to create docker compose files but directly creating it with docker\_container in tasks main file. Then i have my "main" playbook that have all the roles assigned and a playbook only with the service i'm testing. i normally start my configuring a role with a basic template with the task file without many variables. Then deploy using the service playbook and check if everyting is ok in Portainer, see if the container is working and i can access the service. if it's not ok, i change the role and redeploy just the small playbook... repeat until its working when it's working, i start migrating the attributes to variables. ---------------------------------------------------------------------- rrrmmmrrrmmm · 2023-11-23 12:42 I test changes on Vagrant but I _should_ test it with molecule/ansible-test too. ---------------------------------------------------------------------- Trustworthy_Fartzzz · 2023-11-23 15:13 Nah, you can use Ansible’s `assert` for stuff like this. Also, the `docker_compose` module will almost always fail if the container doesn’t start. I do the same as the original commenter only I don’t use jinja2 templates - just the `definition` attribute. DM me and I can add you to mine. It’d require some massaging but I’ve got playbooks for dozens of popular self-hosted services. ---------------------------------------------------------------------- Anycast · 2023-11-23 16:44 I also have handlers built in. If the file changes, the container will automatically restart.