Skip to content

Commit bab4a82

Browse files
committed
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 why minion is `unsupported` * Allow `unsupported` to be overridden at each level within the map
1 parent a3ebe2b commit bab4a82

File tree

8 files changed

+42
-3
lines changed

8 files changed

+42
-3
lines changed

template/config/clean.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- set sls_service_clean = tplroot ~ '.service.clean' %}
78
{%- from tplroot ~ "/map.jinja" import template with context %}
89
910
include:
11+
- {{ sls_fail_if_unsupported }}
1012
- {{ sls_service_clean }}
1113
1214
template-config-clean-file-absent:

template/config/file.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- set sls_package_install = tplroot ~ '.package.install' %}
78
{%- from tplroot ~ "/map.jinja" import template with context %}
89
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
910
1011
include:
12+
- {{ sls_fail_if_unsupported }}
1113
- {{ sls_package_install }}
1214
1315
template-config-file-file-managed:

template/osfingermap.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
# the `os_finger` grain.
1111
---
1212
# os: Ubuntu
13+
Ubuntu-14.04:
14+
unsupported: 'osfinger: Ubuntu 14.04 (does not use `systemd`).'
15+
Ubuntu-16.04: {}
1316
Ubuntu-18.04:
1417
config: /etc/template.d/custom-ubuntu-18.04.conf
1518

1619
# os: CentOS
1720
CentOS-6:
18-
pkg: template-centos-6
19-
config: /etc/template.d/custom-centos-6.conf
20-
CentOS-7: {}
21+
unsupported: 'osfinger: CentOS 6 (does not use `systemd`).'
22+
CentOS-7:
23+
pkg: template-centos-7
24+
config: /etc/template.d/custom-centos-7.conf

template/package/clean.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- set sls_config_clean = tplroot ~ '.config.clean' %}
78
{%- from tplroot ~ "/map.jinja" import template with context %}
89
910
include:
11+
- {{ sls_fail_if_unsupported }}
1012
- {{ sls_config_clean }}
1113
1214
template-package-clean-pkg-removed:

template/package/install.sls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- from tplroot ~ "/map.jinja" import template with context %}
78
9+
include:
10+
- {{ sls_fail_if_unsupported }}
11+
812
template-package-install-pkg-installed:
913
pkg.installed:
1014
- name: {{ template.pkg }}

template/service/clean.sls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- from tplroot ~ "/map.jinja" import template with context %}
78
9+
include:
10+
- {{ sls_fail_if_unsupported }}
11+
812
template-service-clean-service-dead:
913
service.dead:
1014
- name: {{ template.service.name }}

template/service/running.sls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
{#- Get the `tplroot` from `tpldir` #}
55
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
67
{%- set sls_config_file = tplroot ~ '.config.file' %}
78
{%- from tplroot ~ "/map.jinja" import template with context %}
89
910
include:
11+
- {{ sls_fail_if_unsupported }}
1012
- {{ sls_config_file }}
1113
1214
template-service-running-service-running:

template/unsupported.sls

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=sls
3+
4+
{#- Get the `tplroot` from `tpldir` #}
5+
{%- set tplroot = tpldir.split('/')[0] %}
6+
{%- from tplroot ~ "/map.jinja" import template with context %}
7+
8+
{%- if template.unsupported is defined and template.unsupported %}
9+
template-unsupported-test-fail:
10+
test.fail_without_changes:
11+
- name: |
12+
13+
14+
#######################################
15+
# Unsupported minion for this formula #
16+
#######################################
17+
{{ template.unsupported }}
18+
- failhard: True
19+
{%- endif %}

0 commit comments

Comments
 (0)