Ansible implementatipn: how to dispatch reverse proxy and backend server configuration efficiently?

175 views Asked by At

I'm wondering what is the best practice when deploying with Ansible this kind of situation (which is quite common):

  • my.domain.com DNS rule must resolve to my proxy server
  • the proxy server (nginx or whatever) serves content from my backend server

How to dispatch configuration to each server?

What I've done so far:

  • host_var/my.domain.com -> nginx vhost configuration
  • host_var/my.backend.com -> backend configuration

This choice is quite annoying, because it makes me create 2 subdomains each time:

  • my.domain.com to resolve and store proxy configuration
  • my.backend.com to resolve and store backend configuration

It seems OK for 1 single example, but when dealing with lots of services (think microservices) it seems to me it could be improved.

Do you think about another possible implementation?

1

There are 1 answers

1
ceving On BEST ANSWER

If you want to group redundant configuration you have to put your servers in a group in your inventory file.

[frontend]
f1 ansible_host=10.0.0.1
f2 ansible_host=10.0.0.2

[backend]
b1 ansible_host=10.0.1.1
b2 ansible_host=10.0.1.2

And then you create two files

  • group_vars/frontend.yml
  • group_vars/backend.yml

in which you put the configuration for the frontend and backend servers.

Ansible does not require, that you use any domain at all.