1

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:

  1. Create a docker network
  2. Create database container
  3. Clone or update django git repo somewhere in TESTING_SERVER
  4. Create django container
  5. Run django collectstatic command inside django container
  6. Run django migrate command inside django container
  7. 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:

  1. check mysql connection (db is in another server)
  2. Clone or update django git repo somewhere in PRODUCTION_SERVER
  3. Check and restart gunicorn (is the equivalent to create django container)
  4. run django collectstatic
  5. run django migrate
  6. 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?

1

1 Answer 1

0

I would create per "task" a role and use it in the playbook, similar as described in the best practice document.

http://docs.ansible.com/ansible/latest/playbooks_best_practices.html#directory-layout

for example

roles/  
  create_a_docker_network/  
    tasks/  
      main.yml  
  create_database_container/...
  ...  
  Create_nginx_container/

and in the playbook call the roles

testing.yml

- hosts: testserver
  roles:
    - create_a_docker_network
    - create_database_container
    - ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .