From e3f5c683a1d2b34be698cb59d77d379d38458cad Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Sat, 16 Apr 2022 14:42:35 +0200
Subject: Update config() to also search playbook-specific config files
---
lib/util.bash | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
(limited to 'lib/util.bash')
diff --git a/lib/util.bash b/lib/util.bash
index c6ef534..32d61c6 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -14,21 +14,30 @@ config() {
}
config_for() {
+ local host=$1 ; shift
+ local key=$1 ; shift
+ local default=$1 ; shift
+
local default
local file
local files
- local host
- local value
- local key
-
- host=$1 ; shift
- key=$1 ; shift
- default=$1 ; shift
files=(
"$BASHTARD_ETCDIR/hosts.d/$host"
"$BASHTARD_ETCDIR/os.d/${BASHTARD_PLATFORM[key]}"
"$BASHTARD_ETCDIR/defaults"
+ )
+
+ if [[ ! -z "$BASHTARD_PLAYBOOK" ]]
+ then
+ debug "bashtard/config_for" "BASHTARD_PLAYBOOK=$BASHTARD_PLAYBOOK, adding etc entries"
+ files+=(
+ "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/etc/os.d"
+ "$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/etc/defaults"
+ )
+ fi
+
+ files+=(
"$BASHTARD_BASEDIR/etc/os.d/${BASHTARD_PLATFORM[key]}"
"$BASHTARD_BASEDIR/etc/defaults"
)
@@ -36,6 +45,8 @@ config_for() {
# Check configuration files
for file in "${files[@]}"
do
+ debug "bashtard/config_for" "Checking for '$key' in '$file'"
+
[[ ! -f $file ]] && continue
value="$(awk -F= '$1 == "'"$key"'" { print $NF }' "$file")"
--
cgit v1.1