From 28c55aa1a8c82def2ffdb3e000812a5523371ac5 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Fri, 10 Mar 2023 10:44:48 +0100
Subject: Add playbook_path()
---
lib/util.bash | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
(limited to 'lib/util.bash')
diff --git a/lib/util.bash b/lib/util.bash
index e5dbc3f..489ccf1 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -112,7 +112,7 @@ fetch_http_wget() {
# template, they are expected to be written as ${key}.
file_template()
{
- local file="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/$1" ; shift
+ local file="$(playbook_path "base")/share/$1" ; shift
local sedfile
sedfile="$(tmpfile)"
@@ -182,6 +182,24 @@ join_args() {
printf "%s" "$*"
}
+# Convenience function to easily get paths used by the playbook, or to use in
+# your playbook.
+playbook_path() {
+ if [[ -z "$BASHTARD_PLAYBOOK" ]]
+ then
+ crit "bashtard/playbook_path" "Called outside of a playbook"
+ return 1
+ fi
+
+ case "$1" in
+ base) printf "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK" ;;
+ data) printf "$BASHTARD_ETCDIR/data.d/$BASHTARD_PLAYBOOK" ;;
+ *)
+ crit "bashtard/playbook_path" "Invalid path '$1'"
+ return 1
+ esac
+}
+
# Create a temporary directory. Similar to tempfile, but you'll get a directory
# instead.
tmpdir() {
--
cgit v1.1