From a78b90e8bde4029d13a7feb5c1b65ff1113de5f7 Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Wed, 20 Dec 2023 11:43:54 +0100 Subject: [PATCH] fix: better output for cacher tag assignment --- salt/sys-cacher/files/admin/tag.sh | 15 +++++++++++++++ salt/sys-cacher/tag.sls | 11 +++-------- 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100755 salt/sys-cacher/files/admin/tag.sh diff --git a/salt/sys-cacher/files/admin/tag.sh b/salt/sys-cacher/files/admin/tag.sh new file mode 100755 index 0000000..cf1beae --- /dev/null +++ b/salt/sys-cacher/files/admin/tag.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +set -eu + +exclude="$(qvm-ls --no-spinner --raw-list --tags whonix-updatevm \ + | sed "s/^./--exclude &/" | tr "\n" " ")" + +wanted="$(qvm-ls --no-spinner --raw-data --fields=NAME,CLASS --all ${exclude} \ + | awk -v class="TemplateVM" -F "|" '$2 ~ class {print $1}')" + +echo "${wanted}" diff --git a/salt/sys-cacher/tag.sls b/salt/sys-cacher/tag.sls index e4936af..c60afcb 100644 --- a/salt/sys-cacher/tag.sls +++ b/salt/sys-cacher/tag.sls @@ -4,14 +4,9 @@ SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. SPDX-License-Identifier: AGPL-3.0-or-later #} -{% set avoid = salt['cmd.shell']('qvm-ls --no-spinner --raw-list --tags whonix-updatevm') -%} - -{% set exclude = salt['cmd.shell']('for qube in ' ~ avoid ~ '; do exclude="$exclude --exclude $qube"; done; echo "$exclude"') -%} - -{% set wanted = salt['cmd.shell']('qvm-ls --no-spinner --raw-data --fields=NAME,CLASS --all ' ~ exclude ~ ' | awk -F "|" "/|TemplateVM|/{print $1}"') -%} - -{% for tpl in wanted -%} -"{{ tpl }}-cacher-tag": +{% set templates = salt['cmd.script']('salt://' ~ slsdotpath ~ '/files/admin/tag.sh') -%} +{% for tpl in templates.stdout.split("\n") -%} +"{{ slsdotpath }}-tag-for-{{ tpl }}": qvm.tags: - name: {{ tpl }} - add: