fix(snippets): ignore servers or snippets when undefined

nginx.servers_config wants a lightened copy of the nginx map
to render as json; but, when it was trying to remove the
servers and snippets keys from the map it assumed their presence,
causing a KeyError if they were not present by its use of .pop().

While wrapping these in an "if" clause would likely be more
correct, along with replacing .pop() with del (if jinja even
supports that) the simplest change here is to just specify a
default value for .pop(), which obviates the KeyError.

Fixes #274
This commit is contained in:
Jonathon Anderson 2021-01-23 07:04:12 -07:00 committed by Imran Iqbal
parent a55f741901
commit 6cb486dbd2
No known key found for this signature in database
GPG Key ID: 6D8629439D2B7819
2 changed files with 4 additions and 4 deletions

View File

@ -10,8 +10,8 @@
{% set server_states = [] %} {% set server_states = [] %}
{#- _nginx is a lightened copy of nginx map intended to passed in templates #} {#- _nginx is a lightened copy of nginx map intended to passed in templates #}
{%- set _nginx = nginx.copy() %} {%- set _nginx = nginx.copy() %}
{%- do _nginx.pop('snippets') %} {%- do _nginx.pop('snippets') if nginx.snippets is defined %}
{%- do _nginx.pop('servers') %} {%- do _nginx.pop('servers') if nginx.servers is defined %}
# Simple path concatenation. # Simple path concatenation.
# Needs work to make this function on windows. # Needs work to make this function on windows.

View File

@ -8,8 +8,8 @@
{#- _nginx is a lightened copy of nginx map intended to passed in templates #} {#- _nginx is a lightened copy of nginx map intended to passed in templates #}
{%- set _nginx = nginx.copy() %} {%- set _nginx = nginx.copy() %}
{%- do _nginx.pop('snippets') %} {%- do _nginx.pop('snippets') if nginx.snippets is defined %}
{%- do _nginx.pop('servers') %} {%- do _nginx.pop('servers') if nginx.servers is defined %}
nginx_snippets_dir: nginx_snippets_dir:
file.directory: file.directory: