Store mysql root password in a Nomad variable.

This commit is contained in:
2024-01-15 06:34:04 +00:00
parent 5e25d5f858
commit 093c91151a
4 changed files with 60 additions and 8 deletions

50
utils/file_to_nomad_var.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Loads file contents into a nomad variable.
#
# Usage: file_to_nomad_var.sh <filename> <variablename> <var_key>
#
# filename can be - for stdin.
#
# read the var back out with:
# - nomad var get <variablename>
#
# From https://github.com/gerrowadat/nomad-homelab/blob/main/utilities/file_to_nomad_var.sh
function print_usage() {
echo "Usage: ${0} <file or -> <nomad var> <var key>"
}
filename=$1
nomad_var=$2
var_key=$3
if [ "${filename}" != "-" ];
then
if [ ! -f "${filename}" ]
then
echo "${filename} does not exist"
exit
fi
fi
var_contents=$(cat ${filename})
if [[ "${nomad_var}" == "" || "${var_key}" == "" ]];
then
print_usage
exit
fi
echo "Copying ${filename} to ${nomad_var}:${var_key}..."
nomad var put -force -in hcl - <<EOF
path = "${nomad_var}"
items {
${var_key} = <<OMGUNIQUETOKEN
${var_contents}
OMGUNIQUETOKEN
}
EOF