Skip to content

Instantly share code, notes, and snippets.

@evilbulgarian
Created November 29, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilbulgarian/9db75e5f922c59089585e3795d324efe to your computer and use it in GitHub Desktop.
Save evilbulgarian/9db75e5f922c59089585e3795d324efe to your computer and use it in GitHub Desktop.
{% set ind_increment = 4 %}
{%- macro server_config(values, key='', ind=0, lb='\n', delim=';', operator=' ') -%}
{%- for value in values -%}
{%- if value is number or value is string -%}
{{ lb }}{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}
{%- elif value is mapping -%}
{%- for k, v in value.items() -%}
{%- if v is number or v is string -%}
{{ server_config([v], k, ind) }}
{%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%}
{{ lb }}{{ k|indent(ind,True) }}{{ server_config(v,'', 0, '', '')}}{{ delim }}
{%- else %}
{{ lb }}{{ k|indent(ind, True) }} {{ '{' }}
{{- server_config(v, '', ind + ind_increment) }}
{{ '}'|indent(ind, True) }}
{%- endif -%}
{%- endfor -%}
{%- elif value is iterable -%}
{{ server_config(value, ind + ind_increment, delim, operator) }}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
# Nginx server configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.
{{ server_config(config) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment