I need some help with deploying a system I have been working for a year and a half now. In order you can understand my concern, I will explain a little about our infrastructure.
We have a server (let's call it TESTING_SERVER) where we have different testing environments for our system. Each of these environments is running entirely with docker. Each instance of a testing environment consists in: 1. Docker container with nginx acting as a proxy 2. Docker container with a Django web 3. Docker container with mysql
Every time we need to build a new environment for testing purposes (i.e: QA want to test a new feature), we use an ansible playbook which run these tasks on TESTING_SERVER:
- Create a docker network
- Create database container
- Clone or update django git repo somewhere in TESTING_SERVER
- Create django container
- Run django collectstatic command inside django container
- Run django migrate command inside django container
- Create nginx container
In our production environment we have a plain ubuntu server (PRODUCTION_SERVER) running mysql, django and nginx. Every time we have to deploy to production, we run an ansible playbook that (almost) repeat the steps listed above:
- check mysql connection (db is in another server)
- Clone or update django git repo somewhere in PRODUCTION_SERVER
- Check and restart gunicorn (is the equivalent to create django container)
- run django collectstatic
- run django migrate
- check nginx configuration
These two playbooks are different, although they have a lot in common. I was thinking to convert each step to an ansible task and use a conditional to know which tasks (dockerized or direct) should be run. But I will still have different tasks for each step (same playbook but seems a little tricky).
My question is: is there a way to "merge" these playbooks to have just one without repeating ourselves?