Skip to content

Commit 6ccceb7

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(s) why minion is `unsupported`
1 parent a3ebe2b commit 6ccceb7

File tree

8 files changed

+46
-3
lines changed

8 files changed

+46
-3
lines changed

template/config/clean.sls

+2
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

+2
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

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
# the `os_finger` grain.
1111
---
1212
# os: Ubuntu
13+
Ubuntu-14.04:
14+
unsupported:
15+
osfinger: 'Ubuntu 14.04 (does not use `systemd`).'
16+
Ubuntu-16.04: {}
1317
Ubuntu-18.04:
1418
config: /etc/template.d/custom-ubuntu-18.04.conf
1519

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

template/package/clean.sls

+2
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

+4
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

+4
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

+2
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

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
{%- for key, val in template.unsupported.items() %}
18+
* {{ key }}: {{ val }}
19+
{%- endfor %}
20+
- failhard: True
21+
{%- endif %}

0 commit comments

Comments
 (0)