From 1f488b6af3f63aeaa1803d913684a4871f9a9411 Mon Sep 17 00:00:00 2001 From: Andreas Thienemann Date: Tue, 8 Dec 2020 20:58:12 +0100 Subject: [PATCH] Do not pass full apache context to vhost templates. The full apache context variable can grow quite large if using multiple vhosts with SSL certificates. With 200 sites the apache variable is being rendered 200 times which resuls in observed renderer output of about 950MB... state.apply will result with MemoryErrors in such cases. This PR modifies the templating code to _only_ use a per site context and pass a trimmed down copy of the apache context instead of the full. Drive-By: Correct indentation for context variables. Drive-By: Remove duplicate map/apache functionality. Only use map. --- apache/config/vhosts/proxy.tmpl | 4 ++-- apache/config/vhosts/standard.sls | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/apache/config/vhosts/proxy.tmpl b/apache/config/vhosts/proxy.tmpl index 80ba3f4..bfebf0b 100644 --- a/apache/config/vhosts/proxy.tmpl +++ b/apache/config/vhosts/proxy.tmpl @@ -81,7 +81,7 @@ 'Dav': loc.get('Dav', False), } %} - {%- if apache.version == '2.4' %} + {%- if map.version == '2.4' %} {% if lvals.get('Require') != False %}Require {{ lvals.Require }}{% endif %} {%- else %} {% if lvals.get('Order') != False %}Order {{ lvals.Order }}{% endif %} @@ -98,7 +98,7 @@ 'Dav': locmat.get('Dav', False), } %} - {%- if apache.version == '2.4' %} + {%- if map.version == '2.4' %} {% if lmvals.get('Require') != False %}Require {{ lmvals.Require }}{% endif %} {%- else %} {% if lmvals.get('Order') != False %}Order {{ lmvals.Order }}{% endif %} diff --git a/apache/config/vhosts/standard.sls b/apache/config/vhosts/standard.sls index 7efb922..6fd940a 100644 --- a/apache/config/vhosts/standard.sls +++ b/apache/config/vhosts/standard.sls @@ -5,6 +5,10 @@ {%- set sls_package_install = tplroot ~ '.package.install' %} {%- set sls_service_running = tplroot ~ '.service.running' %} {%- from tplroot ~ "/map.jinja" import apache with context %} +{#- The apache variable can grow _very_ large, especially the sites subkey. + Create a trimmed copy with config variables. #} +{%- set map = apache %} +{%- do map.pop('sites', None) %} include: - {{ sls_package_install }} @@ -20,10 +24,9 @@ apache-config-vhosts-standard-{{ id }}: - template: {{ apache.get('template_engine', 'jinja') }} - makedirs: True - context: - apache: {{ apache|json }} - id: {{ id|json }} - site: {{ site|json }} - map: {{ apache|json }} + id: {{ id|json }} + site: {{ site|json }} + map: {{ map|json }} - require: - pkg: apache-package-install-pkg-installed - watch_in: