Skip to content

Commit

Permalink
feat(unsupported): prevent formula running on unsupported minions
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
myii committed Apr 23, 2019
1 parent a741a47 commit 7414fa0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions template/config/init.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}

include:
- {{ sls_fail_if_unsupported }}
- .file
4 changes: 4 additions & 0 deletions template/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}

include:
- {{ sls_fail_if_unsupported }}
- .package
- .config
- .service
9 changes: 6 additions & 3 deletions template/osfamilymap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ FreeBSD: {}

OpenBSD: {}

Solaris: {}
Solaris:
unsupported: 'osfamily: Solaris.'

Windows: {}
Windows:
unsupported: 'osfamily: Windows.'

MacOS: {}
MacOS:
unsupported: 'osfamily: MacOS.'
10 changes: 7 additions & 3 deletions template/osfingermap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
# 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: 'osfinger: CentOS 6 (does not use `systemd`).'
CentOS-7:
pkg: template-centos-7
config: /etc/template.d/custom-centos-7.conf
3 changes: 2 additions & 1 deletion template/osmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Ubuntu:
pkg: template-ubuntu
config: /etc/template.d/custom-ubuntu.conf

Raspbian: {}
Raspbian:
unsupported: 'os: Raspbian (`armhf` architecture).'

# os_family: RedHat
Fedora:
Expand Down
4 changes: 4 additions & 0 deletions template/package/init.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}

include:
- {{ sls_fail_if_unsupported }}
- .install
4 changes: 4 additions & 0 deletions template/service/init.sls
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_fail_if_unsupported = tplroot ~ '.unsupported' %}

include:
- {{ sls_fail_if_unsupported }}
- .running
19 changes: 19 additions & 0 deletions template/unsupported.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- 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 and template.unsupported %}
template-unsupported-test-fail:
test.fail_without_changes:
- name: |
#######################################
# Unsupported minion for this formula #
#######################################
{{ template.unsupported }}
- failhard: True
{%- endif %}

0 comments on commit 7414fa0

Please sign in to comment.