I’m new to ansible and I’m wondering the best strategy to manage several machines (bare metal, vps) that host docker-compose stacks.
For now, I wrote a generic role based on templates and files that loops on a variable that defines the docker-compose stacks to deploy.
That looks like this:
[...]
docker_stack_list:
- template: reverse_proxy
- template: metrics
- template: nginx
dir: files_foo_bar
url: files.foo_bar
with_redirect: True
- template: nginx
dir: files2_foo_bar
url: files2.foo_bar
with_redirect: True
[...]
The point is that I’m thinking about writing a role per docker stack and then a playbook per host that would look like this:
---
- name: Deploy All Docker Stacks
hosts: foo.bar
remote_user: root
roles:
- deploy_reverse_proxy
- deploy_metrics
- { role: deploy_nginx, dir: files_foo_bar, url: files.foo_bar }
- { role: deploy_nginx, dir: files2_foo_bar, url: files2.foo_bar }
On the first solution, my host configuration is quasi all included in my host variable file.
On the second solution, my host configuration is quasi all included in my playbook variable file.
Does anyone already considered such alternatives ?