2016-03-02 17:52:19 +08:00
|
|
|
#!/usr/bin/env bash
|
2016-02-29 23:35:07 +08:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2017-05-15 21:49:45 +08:00
|
|
|
#############
|
|
|
|
# VARIABLES #
|
|
|
|
#############
|
|
|
|
|
2016-02-29 23:35:07 +08:00
|
|
|
basedir=$(dirname "$0")
|
2017-05-15 21:49:45 +08:00
|
|
|
no_header="ceph-docker-common" # pipe separated list of roles with no header, MUST end with '$', e.g: 'foo$|bar$'
|
|
|
|
merge_in_all="ceph-common$|ceph-docker-common$" # pipe separated list of roles you want to merge in all.yml.sample, MUST end with '$', e.g: 'foo$|bar$'
|
2016-02-29 23:35:07 +08:00
|
|
|
|
2016-03-02 17:52:19 +08:00
|
|
|
|
2017-05-15 21:49:45 +08:00
|
|
|
#############
|
|
|
|
# FUNCTIONS #
|
|
|
|
#############
|
|
|
|
|
|
|
|
populate_header () {
|
2016-03-02 17:52:19 +08:00
|
|
|
cat <<EOF > "$basedir"/group_vars/"$output"
|
2016-02-29 23:35:07 +08:00
|
|
|
---
|
|
|
|
# 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
|
2017-05-15 21:49:45 +08:00
|
|
|
}
|
2016-02-29 23:35:07 +08:00
|
|
|
|
2017-05-15 21:49:45 +08:00
|
|
|
generate_group_vars_file () {
|
2016-03-02 17:52:19 +08:00
|
|
|
if [ "$(uname)" == "Darwin" ]; then
|
2017-05-15 16:38:36 +08:00
|
|
|
sed '/^---/d; s/^\([A-Za-z[:space:]]\)/#\1/' \
|
|
|
|
"$defaults" >> "$basedir"/group_vars/"$output"
|
2016-03-02 17:52:19 +08:00
|
|
|
echo >> "$basedir"/group_vars/"$output"
|
2017-05-15 16:56:33 +08:00
|
|
|
elif [ "$(uname -s)" == "Linux" ]; then
|
2016-02-29 23:35:07 +08:00
|
|
|
sed '/^---/d; s/^\([A-Za-z[:space:]].\+\)/#\1/' \
|
2017-05-15 16:38:36 +08:00
|
|
|
"$defaults" >> "$basedir"/group_vars/"$output"
|
2016-02-29 23:35:07 +08:00
|
|
|
echo >> "$basedir"/group_vars/"$output"
|
2016-03-02 17:52:19 +08:00
|
|
|
else
|
|
|
|
echo "Unsupported platform"
|
|
|
|
exit 1
|
|
|
|
fi
|
2017-05-15 21:49:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
########
|
|
|
|
# MAIN #
|
|
|
|
########
|
|
|
|
|
|
|
|
for role in "$basedir"/roles/ceph-*; do
|
|
|
|
rolename=$(basename "$role")
|
|
|
|
|
|
|
|
if echo "$rolename" | grep -qE "$merge_in_all"; then
|
|
|
|
output="all.yml.sample"
|
|
|
|
elif [[ $rolename == "ceph-agent" ]]; then
|
|
|
|
output="agent.yml.sample"
|
|
|
|
elif [[ $rolename == "ceph-fetch-keys" ]]; then
|
|
|
|
output="ceph-fetch-keys.yml.sample"
|
|
|
|
else
|
|
|
|
output="${rolename:5}s.yml.sample"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Do not re-regenerate the header for certain roles
|
|
|
|
# since we merge them in all.yml.sample
|
|
|
|
if ! echo "$rolename" | grep -qE "$no_header"; then
|
|
|
|
populate_header
|
|
|
|
fi
|
|
|
|
|
|
|
|
defaults="$role"/defaults/main.yml
|
|
|
|
if [[ ! -f $defaults ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
generate_group_vars_file
|
2016-02-29 23:35:07 +08:00
|
|
|
done
|