From 23df36ded97e740733f9bf30c89e81f944576235 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Sat, 4 Feb 2023 13:45:55 +0100 Subject: [PATCH] feat(servers_config): enable configs by default Don't require `enabled: true` - helps distributions without separate available/enabled directories and prevents error: "Rendering SLS 'production:nginx.servers' failed: Jinja variable 'list object' has no attribute 'enabled'" Signed-off-by: Georg Pfuetzenreuter --- nginx/servers_config.sls | 9 +++++---- pillar.example | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nginx/servers_config.sls b/nginx/servers_config.sls index 6652d64..3f602fc 100644 --- a/nginx/servers_config.sls +++ b/nginx/servers_config.sls @@ -101,6 +101,7 @@ nginx_server_available_dir: # Managed enabled/disabled state for servers {% for server, settings in nginx.servers.managed.items() %} +{% set server_enabled = settings.enabled | default(True) %} {% set conf_state_id = 'server_conf_' ~ loop.index0 %} {% if 'deleted' in settings and settings.deleted %} {{ conf_state_id }}: @@ -108,7 +109,7 @@ nginx_server_available_dir: - name: {{ server_curpath(server) }} {% do server_states.append(conf_state_id) %} {% else %} -{% if settings.enabled == True %} +{% if server_enabled == True %} {{ conf_state_id }}: file.managed: {{ sls_block(nginx.servers.managed_opts) }} @@ -142,7 +143,7 @@ nginx_server_available_dir: {% endif %} {% endif %} -{% if settings.enabled != None %} +{% if settings.enabled is defined and server_enabled != None %} {% set status_state_id = 'server_state_' ~ loop.index0 %} {%- set enabled_dir = path_join(server, nginx.servers.managed.get(server).get('enabled_dir', nginx.lookup.server_enabled)) -%} {%- set available_dir = path_join(server, nginx.servers.managed.get(server).get('available_dir', nginx.lookup.server_available)) -%} @@ -151,9 +152,9 @@ nginx_server_available_dir: {% if 'deleted' in settings and settings.deleted %} {{ manage_status(server, False, True) }} {% else %} -{{ manage_status(server, settings.enabled, False) }} +{{ manage_status(server, server_enabled, False) }} {% endif %} -{% if settings.enabled == True %} +{% if server_enabled == True %} - require: - file: {{ conf_state_id }} {% endif %} diff --git a/pillar.example b/pillar.example index 7b610ef..12a5347 100644 --- a/pillar.example +++ b/pillar.example @@ -198,8 +198,9 @@ nginx: # relative filename of server file # (defaults to '/etc/nginx/sites-available/mysite') mysite: - # may be true, false, or None where true is enabled, false, disabled, + # may be true, false, or None where true is enabled, false is disabled, # and None indicates no action + # true without ".disabled" management if not specified enabled: true # This let's you add dependencies on other resources being applied for a