Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): use separate defaults for all states #247

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions nginx/files/default/passenger.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% set indent_increment = 4 %}

{%- macro nginx_block(value, key=None, operator=' ', delim=';', ind=0) -%}
{%- if value != None -%}
{%- if value is number or value is string -%}
{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}
{%- elif value is mapping -%}
{{ key|indent(ind, True) }}{{ operator }}{{ '{' }}
{%- for k, v in value.items() %}
{%- if k != 'include' %}
{{ nginx_block(v, k, operator, delim, (ind + indent_increment)) }}
{%- endif %}
{%- endfor %}
{%- if 'include' in value.keys() %}
{{ nginx_block(value['include'], 'include', operator, delim, (ind + indent_increment)) }}
{%- endif %}
{{ '}'|indent(ind, True) }}
{%- elif value is iterable -%}
{%- for v in value %}
{{ nginx_block(v, key, operator, delim, ind) }}
{%- endfor -%}
{%- else -%}
{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}
{%- endif -%}
{%- else -%}
{%- endif -%}
{%- endmacro -%}

# Default nginx server configuration
#
# **** DO NOT EDIT THIS FILE ****
#
# This file is managed by Salt.

{% if 'load_module' in config.keys() %}
{{ nginx_block(config.pop('load_module'), 'load_module') }}
{%- endif -%}

{% if 'include' in config.keys() %}
{{ nginx_block(config.pop('include'), 'include') }}
{%- endif -%}

{% for key, value in config.items() %}
{{ nginx_block(value, key) }}
{%- endfor -%}
29 changes: 29 additions & 0 deletions nginx/files/default/snippet.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% 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 -%}
{{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}{{ lb }}
{%- 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) -%}
{{ server_config(v, k, ind) }}
{%- else -%}
{{ lb }}{{ k|indent(ind, True) }} {{ '{' }}
{{ server_config(v, '', ind + ind_increment) -}}
{{ '}'|indent(ind, True) }}{{ lb }}
{%- 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) }}
8 changes: 7 additions & 1 deletion nginx/passenger.sls
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
{% if salt['grains.get']('os_family') in ['Debian', 'RedHat'] %}
include:
- nginx.pkg
- nginx.config
- nginx.service
{%- if nginx.snippets is defined %}
- nginx.snippets
{%- endif %}
- nginx.servers
- nginx.certificates

passenger_install:
pkg.installed:
Expand All @@ -29,7 +35,7 @@ passenger_config:
file.managed:
{{ sls_block(nginx.server.opts) }}
- name: {{ nginx.lookup.passenger_config_file }}
- source: {{ files_switch(['nginx.conf'],
- source: {{ files_switch(['passenger.conf'],
'passenger_config_file_managed'
)
}}
Expand Down
2 changes: 1 addition & 1 deletion nginx/snippets.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nginx_snippets_dir:
nginx_snippet_{{ snippet }}:
file.managed:
- name: {{ nginx.lookup.snippets_dir ~ '/' ~ snippet }}
- source: {{ files_switch([ snippet, 'server.conf' ],
- source: {{ files_switch([ snippet, 'snippet.conf' ],
'nginx_snippet_file_managed'
)
}}
Expand Down
6 changes: 3 additions & 3 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,18 @@ nginx:
# All aspects of path/file resolution are customisable using the options below.
# This is unnecessary in most cases; there are sensible defaults.
# Path pattern: salt://{{ path_prefix or 'nginx' }}/{{ dirs.files or 'files' }}/{{ dirs.default or 'default' }}
# path_prefix: template_alt
# path_prefix: template_alt
# dirs:
# files: files_alt
# default: default_alt
source_files:
nginx_config_file_managed:
- alt_nginx.conf
passenger_config_file_managed:
- alt_nginx.conf
- alt_passenger.conf
server_conf_file_managed:
- alt_server.conf
nginx_systemd_service_file:
- alt_nginx.service
nginx_snippet_file_managed:
- alt_server.conf
- alt_snippet.conf