From b396b24fe456de7001b2cc013814ada189351e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Wed, 23 Sep 2020 15:51:03 -0300 Subject: [PATCH] feat(config): validate config before applying --- nginx/config.sls | 3 +++ nginx/map.jinja | 1 + pillar.example | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/nginx/config.sls b/nginx/config.sls index 3cd00b5..82b181f 100644 --- a/nginx/config.sls +++ b/nginx/config.sls @@ -31,3 +31,6 @@ nginx_config: - context: config: {{ nginx.server.config|json(sort_keys=False) }} {% endif %} +{% if nginx.check_config_before_apply %} + - check_cmd: /usr/sbin/nginx -t -c +{% endif %} diff --git a/nginx/map.jinja b/nginx/map.jinja index c273349..d66b17c 100644 --- a/nginx/map.jinja +++ b/nginx/map.jinja @@ -112,6 +112,7 @@ 'install_from_ppa': False, 'install_from_repo': False, 'install_from_phusionpassenger': False, + 'check_config_before_apply': False, 'ppa_version': 'stable', 'source_version': '1.10.0', 'source_hash': '8ed647c3dd65bc4ced03b0e0f6bf9e633eff6b01bac772bcf97077d58bc2be4d', diff --git a/pillar.example b/pillar.example index 3654979..ce6109b 100644 --- a/pillar.example +++ b/pillar.example @@ -28,6 +28,17 @@ nginx: source_version: '1.10.0' source_hash: '' + # Check the configuration before applying: + # To prevent applying a configuration that might break nginx, set this + # parameter to true so the configuration is checked BEFORE applying. If + # the check fails, the state will fail and it won't be deployed. + # CAVEAT: As the configuration file is created in a temp dir, it can't + # have relative references or it will fail to check. You'll need to + # specify full paths where required (ie, `include`, `load_module`, + # `snippets`, etc.0 + # Defaults to false + check_config_before_apply: false + # These are usually set by grains in map.jinja # Typically you can comment these out. lookup: