python - how to implement a multi-tenant configuration solution in ansible -


one common pattern i've seen in many applications multitenancy. basically, i'm configuring application has of configuration values different based on country. way i've managed configuration using "partners" dictionary in yaml:

--- partners:     us:          url: 'http://company.com'     uk:          url: 'http://company.co.uk'     fr:          url: 'https://company.fr'     ch:          url: 'https://company.fr' 

and thus, when serving customers identified come 'us' we'll use 1 value url different if application identifies coming 'fr'.

then, when configuring template, similar to:

template:  xxxx with_items: partners_list 

then, in template use partners[item].url access variable. thus, 1 template, i'm configuring multiple files different values according partner. bear account of values common though (most configurations not in partners dict).

this less satisfactory.

what have "dynamic variables" system implement similar "context". like, simple , portable loads contexts main namespace. allows me reference "url" , automatically try use partners[item].url , if it's not there, use plain url.

one solution use partners[item].url | default(url), verbose , leads bit of confusion imho. i'd rather not add clutter in templates.

another possibility "{% set_context 'us' %}" // "{% end_context %}" in jinja , overlap variables in dict first level variables, context. think satisfactory well. problem is, can extend jinja in way can put in repo, without needing touch everyone's ansible/jinja installations? in other words, can choose templating engine in ansible, can write extended jinja (which able lookup variables) ansible use?

if change partners dictionary list of hashes can accomplish you're looking for. way accomplish multi-tenancy in application support. here's 1 approach example:

partners:   - name:      url: 'http://company.com'   - name: uk     url: 'http://company.co.uk'   - name: fr      url: 'https://company.fr'   - name: ch      url: 'https://company.fr' 

render template:

template:  xxxx with_items: partners 

now can reference site url via item.url in template.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -