Przeglądaj źródła

Merge pull request #168 from dseira/master

New Feature/Improvement - Added deleted option to be able to remove site files
master
David Seira 7 lat temu
rodzic
commit
69e9b47baf
2 zmienionych plików z 31 dodań i 5 usunięć
  1. +27
    -5
      nginx/ng/servers_config.sls
  2. +4
    -0
      pillar.example

+ 27
- 5
nginx/ng/servers_config.sls Wyświetl plik

@@ -37,7 +37,7 @@
{%- endmacro %}

# Creates the sls block that manages symlinking / renaming servers
{% macro manage_status(server, state) -%}
{% macro manage_status(server, state, deleted) -%}
{%- set anti_state = {True:False, False:True}.get(state) -%}
{% if state == True %}
{%- if nginx.lookup.server_use_symlink %}
@@ -46,20 +46,30 @@
- name: {{ server_path(server, state) }}
- target: {{ server_path(server, anti_state) }}
{%- else %}
{%- if deleted == True %}
file.absent:
- name: {{ server_path(server, state) }}
{%- else %}
file.rename:
{{ sls_block(nginx.servers.rename_opts) }}
- name: {{ server_path(server, state) }}
- source: {{ server_path(server, anti_state) }}
{%- endif %}
{%- endif %}
{%- elif state == False %}
{%- if nginx.lookup.server_use_symlink %}
file.absent:
- name: {{ server_path(server, anti_state) }}
{%- else %}
{%- if deleted == True %}
file.absent:
- name: {{ server_path(server, state) }}
{%- else %}
file.rename:
{{ sls_block(nginx.servers.rename_opts) }}
- name: {{ server_path(server, state) }}
- source: {{ server_path(server, anti_state) }}
{%- endif %}
{%- endif -%}
{%- endif -%}
{%- endmacro %}
@@ -84,13 +94,18 @@ nginx_server_available_dir:

# Managed enabled/disabled state for servers
{% for server, settings in nginx.servers.managed.items() %}
{% if settings.config != None %}
{% set conf_state_id = 'server_conf_' ~ loop.index0 %}
{% if 'deleted' in settings and settings.deleted %}
{{ conf_state_id }}:
file.absent:
- name: {{ server_curpath(server) }}
{% else %}
{% if settings.config != None and settings.enabled == True %}
{% if 'source_path' in settings.config %}
{% set source_path = settings.config.source_path %}
{% else %}
{% set source_path = 'salt://nginx/ng/files/server.conf' %}
{% endif %}
{% set conf_state_id = 'server_conf_' ~ loop.index0 %}
{{ conf_state_id }}:
file.managed:
{{ sls_block(nginx.servers.managed_opts) }}
@@ -107,16 +122,23 @@ nginx_server_available_dir:
{% endif %}
{% do server_states.append(conf_state_id) %}
{% endif %}
{% endif %}

{% if settings.enabled != None %}
{% set status_state_id = 'server_state_' ~ loop.index0 %}
{{ status_state_id }}:
{{ manage_status(server, settings.enabled) }}
{% if settings.config != None %}
{% if 'deleted' in settings and settings.deleted %}
{{ manage_status(server, False, True) }}
{% else %}
{{ manage_status(server, settings.enabled, False) }}
{% endif %}
{% if settings.config != None and settings.enabled == True %}
- require:
- file: {{ conf_state_id }}
{% endif %}

{% if 'deleted' not in settings or ( 'deleted' in settings and settings.deleted == False ) %}
{% do server_states.append(status_state_id) %}
{% endif %}
{% endif %}
{% endfor %}

+ 4
- 0
pillar.example Wyświetl plik

@@ -105,6 +105,10 @@ nginx:
mysite: # relative pathname of the server file
# may be True, False, or None where True is enabled, False, disabled, and None indicates no action
enabled: True
# Remove the site config file. Nice to clean up the conf.d (or sites-available).
# It also remove the symlink (if it is exists).
# The site MUST be disabled before delete it (if not the nginx is not reloaded).
deleted: True
###########
## Modify 'available_dir' AND 'enabled_dir' '/etc/nginx' location to alternative value.
###########

Ładowanie…
Anuluj
Zapisz