Skip to content

Commit 9fed933

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 9fed933

File tree

8 files changed

+50
-7
lines changed

8 files changed

+50
-7
lines changed

template/config/init.sls

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls
33

4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
6+
47
include:
8+
- {{ sls_fail_if_unsupported }}
59
- .file

template/init.sls

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls
33

4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
6+
47
include:
8+
- {{ sls_fail_if_unsupported }}
59
- .package
610
- .config
711
- .service

template/osfamilymap.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ FreeBSD: {}
3333

3434
OpenBSD: {}
3535

36-
Solaris: {}
36+
Solaris:
37+
unsupported: 'osfamily: Solaris.'
3738

38-
Windows: {}
39+
Windows:
40+
unsupported: 'osfamily: Windows.'
3941

40-
MacOS: {}
42+
MacOS:
43+
unsupported: 'osfamily: MacOS.'

template/osfingermap.yaml

+7-3
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/osmap.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Ubuntu:
1414
pkg: template-ubuntu
1515
config: /etc/template.d/custom-ubuntu.conf
1616

17-
Raspbian: {}
17+
Raspbian:
18+
unsupported: 'os: Raspbian (`armhf` architecture).'
1819

1920
# os_family: RedHat
2021
Fedora:

template/package/init.sls

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls
33

4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
6+
47
include:
8+
- {{ sls_fail_if_unsupported }}
59
- .install

template/service/init.sls

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22
# vim: ft=sls
33

4+
{%- set tplroot = tpldir.split('/')[0] %}
5+
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}
6+
47
include:
8+
- {{ sls_fail_if_unsupported }}
59
- .running

template/unsupported.sls

+19
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)