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(s) why minion is `unsupported`
  • Loading branch information
myii committed Apr 22, 2019
1 parent a3ebe2b commit b05814e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions template/config/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions template/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions template/osfingermap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions template/package/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions template/package/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 4 additions & 0 deletions template/service/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions template/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions template/unsupported.sls
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit b05814e

Please sign in to comment.