From b05814ef4b1e40353609bdd5eceef0f84f5c1b79 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Mon, 22 Apr 2019 06:00:13 +0100 Subject: [PATCH] feat(unsupported): prevent formula running on unsupported minions * https://freenode.logbot.info/saltstack-formulas/20190421#c2129159 * Use `failhard` to prevent execution if `unsupported` has been set * Show reason(s) why minion is `unsupported` --- template/config/clean.sls | 2 ++ template/config/file.sls | 2 ++ template/osfingermap.yaml | 11 ++++++++--- template/package/clean.sls | 2 ++ template/package/install.sls | 4 ++++ template/service/clean.sls | 4 ++++ template/service/running.sls | 2 ++ template/unsupported.sls | 21 +++++++++++++++++++++ 8 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 template/unsupported.sls diff --git a/template/config/clean.sls b/template/config/clean.sls index 9e644d36..c213c9fe 100644 --- a/template/config/clean.sls +++ b/template/config/clean.sls @@ -3,10 +3,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- set sls_service_clean = tplroot ~ '.service.clean' %} {%- from tplroot ~ "/map.jinja" import template with context %} include: + - {{ sls_fail_if_unsupported }} - {{ sls_service_clean }} template-config-clean-file-absent: diff --git a/template/config/file.sls b/template/config/file.sls index fc07019d..4c6dfb49 100644 --- a/template/config/file.sls +++ b/template/config/file.sls @@ -3,11 +3,13 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- set sls_package_install = tplroot ~ '.package.install' %} {%- from tplroot ~ "/map.jinja" import template with context %} {%- from tplroot ~ "/libtofs.jinja" import files_switch with context %} include: + - {{ sls_fail_if_unsupported }} - {{ sls_package_install }} template-config-file-file-managed: diff --git a/template/osfingermap.yaml b/template/osfingermap.yaml index 60559286..ef588233 100644 --- a/template/osfingermap.yaml +++ b/template/osfingermap.yaml @@ -10,11 +10,16 @@ # the `os_finger` grain. --- # os: Ubuntu +Ubuntu-14.04: + unsupported: + osfinger: 'Ubuntu 14.04 (does not use `systemd`).' +Ubuntu-16.04: {} Ubuntu-18.04: config: /etc/template.d/custom-ubuntu-18.04.conf # os: CentOS CentOS-6: - pkg: template-centos-6 - config: /etc/template.d/custom-centos-6.conf -CentOS-7: {} + unsupported: 'CentOS 6 (does not use `systemd`).' +CentOS-7: + pkg: template-centos-7 + config: /etc/template.d/custom-centos-7.conf diff --git a/template/package/clean.sls b/template/package/clean.sls index 8d2660f9..cd50ee42 100644 --- a/template/package/clean.sls +++ b/template/package/clean.sls @@ -3,10 +3,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- set sls_config_clean = tplroot ~ '.config.clean' %} {%- from tplroot ~ "/map.jinja" import template with context %} include: + - {{ sls_fail_if_unsupported }} - {{ sls_config_clean }} template-package-clean-pkg-removed: diff --git a/template/package/install.sls b/template/package/install.sls index 78bdb5ea..e5a05a38 100644 --- a/template/package/install.sls +++ b/template/package/install.sls @@ -3,8 +3,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- from tplroot ~ "/map.jinja" import template with context %} +include: + - {{ sls_fail_if_unsupported }} + template-package-install-pkg-installed: pkg.installed: - name: {{ template.pkg }} diff --git a/template/service/clean.sls b/template/service/clean.sls index 2074193d..58669d40 100644 --- a/template/service/clean.sls +++ b/template/service/clean.sls @@ -3,8 +3,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- from tplroot ~ "/map.jinja" import template with context %} +include: + - {{ sls_fail_if_unsupported }} + template-service-clean-service-dead: service.dead: - name: {{ template.service.name }} diff --git a/template/service/running.sls b/template/service/running.sls index d668f85f..2175cf26 100644 --- a/template/service/running.sls +++ b/template/service/running.sls @@ -3,10 +3,12 @@ {#- Get the `tplroot` from `tpldir` #} {%- set tplroot = tpldir.split('/')[0] %} +{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %} {%- set sls_config_file = tplroot ~ '.config.file' %} {%- from tplroot ~ "/map.jinja" import template with context %} include: + - {{ sls_fail_if_unsupported }} - {{ sls_config_file }} template-service-running-service-running: diff --git a/template/unsupported.sls b/template/unsupported.sls new file mode 100644 index 00000000..b98c5bc7 --- /dev/null +++ b/template/unsupported.sls @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# vim: ft=sls + +{#- Get the `tplroot` from `tpldir` #} +{%- set tplroot = tpldir.split('/')[0] %} +{%- from tplroot ~ "/map.jinja" import template with context %} + +{%- if template.unsupported is defined %} +template-unsupported-test-fail: + test.fail_without_changes: + - name: | + + + ####################################### + # Unsupported minion for this formula # + ####################################### + {%- for key, val in template.unsupported.items() %} + * {{ key }}: {{ val }} + {%- endfor %} + - failhard: True +{%- endif %}