S
S
StopDesign2014-08-11 00:47:34
Software Deployment
StopDesign, 2014-08-11 00:47:34

What structure should I choose for an Ansible config with multiple sites on a host?

There is a certain infrastructure managed through Ansible. The infrastructure has virtual machines with sites on django. One virtual machine can have several sites or only one. How to organize the Ansible config to make it as easy as possible to add a new site (to an existing virtual machine or to a new one)?
(I call a site a separate instance of Django or something else that is given through nginx as a separate website on its own domain or on several. Each site is a separate server in the nginx config)
I see two options.
Cheat variant We
specify in inventory.ini each site as a separate host:

[real_host_name]
site_name.ru ansible_ssh_host=11.22.33.44
another_site.com ansible_ssh_host=11.22.33.44

And then in the host_vars/*.yml files there will be variables related to a separate site, and group_vars/host_name.yml will be responsible for the settings of the virtual machine/server.
The main playbook will look like this:
- hosts: real_host_name
  roles:
    - common
    - nginx
    .... и другие общие задачи — настроить локаль, поставить пакеты, создать пользователей

- hosts: site_name.ru
  roles:
    - nginx_site
    - deploy
    - django
  ... и другие задачи, относящиеся к конкретному сайту — создать директории проектов,
  выкатить код, положить локальные конфиги

pros:
- fits comfortably into the standard structure
cons:
- it doesn't look like the site was meant by the host...
- the common real_host_name host config will be executed several times (according to the number of sites on it)
"Correct"
Specify only one in inventory.ini host, and sites are added to the playbook, apparently. But I'm new to setting up Ansible, and I don't know where to put variables and what to write in the playbook so that I don't get unreadable noodles.
Perhaps you need to create a general playbook and one playbook for each site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sevmax, 2015-08-06
@sevmax

Break the big playbook into a number of small ones:
real_host_name.yml
site_name_ru.yml
And describe in them what roles you need to perform.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question