ceph-ansible/generate_group_vars_sample.sh

39 lines
969 B
Bash

#!/bin/bash
set -euo pipefail
basedir=$(dirname "$0")
for role in "$basedir"/roles/ceph-*; do
rolename=$(basename "$role")
if [[ $rolename == "ceph-common" ]]; then
output="all.sample"
elif [[ $rolename == "ceph-agent" ]]; then
output="agent.sample"
elif [[ $rolename == "ceph-fetch-keys" ]]; then
continue
else
output="${rolename:5}s.sample"
fi
cat <<EOF > "$basedir"/group_vars/"$output"
---
# Variables here are applicable to all host groups NOT roles
# This sample file generated by $(basename "$0")
# Dummy variable to avoid error because ansible does not recognize the
# file as a good configuration file when no variable in it.
dummy:
EOF
defaults="$role"/defaults/main.yml
if [[ ! -f $defaults ]]; then
continue
fi
sed '/^---/d; s/^\([A-Za-z[:space:]].\+\)/#\1/' \
"$defaults" >> "$basedir"/group_vars/"$output"
echo >> "$basedir"/group_vars/"$output"
done