Ansible and Docker stacks
Curious to get opinions on a best practice for deploying Docker-based stacks via Ansible.
Currently, I have a Git repo for each host that contains a docker-compose.yml, which defines the containers I want running on that host. Pre-Ansible, I would log into each host, pull the latest, and run docker-compose up -d. Now that I’m managing my hosts via a series of playbooks, I’m pondering the best way to deploy these stacks. I see two ideas:
- Keep the stack configuration in its own repo. In the playbook, focus on pulling the latest repo and spinning it up (using ansible.builtin.git and community.general.docker_compose, respectively).
- Take the stack information in each repo and translate it to a series of tasks in each playbook (using community.general.docker_container).
I’m currently doing #1 because there’s a nice separation of concerns between stack configuration and playbook; if I ever need to manipulate the stack directly, I can log into the host without Ansible.
That said, the other side of my brain likes the idea of a single source of truth for the entire infrastructure, configuration, and stack. In that case, putting everything into a single playbook sounds appetizing.
I’ve been chewing on this for quite a while and haven’t had any revelations, so I’m reaching out to you all for inspiration. Thanks!
Posted Feb 2, 2021, 5:50 PM UTC · edited
I’d keep them separate. Docker is docker and ansible is just a way of deploying your ‘stack’.