2016-03-02 17:52:19 +08:00
#!/usr/bin/env bash
2016-02-29 23:35:07 +08:00
set -euo pipefail
2017-08-02 16:35:26 +08:00
2017-05-15 21:49:45 +08:00
#############
# VARIABLES #
#############
2016-02-29 23:35:07 +08:00
basedir = $( dirname " $0 " )
2020-11-26 17:48:49 +08:00
do_not_generate = " (ceph-common|ceph-container-common|ceph-fetch-keys) $" # pipe separated list of roles we don't want to generate sample file, 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 ( ) {
2017-08-04 04:37:12 +08:00
for i in $output ; do
cat <<EOF > " $basedir " /group_vars/" $i "
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-08-04 04:37:12 +08:00
done
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 ( ) {
2017-08-04 04:37:12 +08:00
for i in $output ; do
if [ " $( uname) " = = "Darwin" ] ; then
sed '/^---/d; s/^\([A-Za-z[:space:]]\)/#\1/' \
" $defaults " >> " $basedir " /group_vars/" $i "
echo >> " $basedir " /group_vars/" $i "
elif [ " $( uname -s) " = = "Linux" ] ; then
sed '/^---/d; s/^\([A-Za-z[:space:]].\+\)/#\1/' \
" $defaults " >> " $basedir " /group_vars/" $i "
echo >> " $basedir " /group_vars/" $i "
else
echo "Unsupported platform"
exit 1
fi
done
2017-05-15 21:49:45 +08:00
}
2017-08-04 04:37:12 +08:00
rhcs_edits ( ) {
tail -n +1 rhcs_edits.txt | while IFS = read -r option; do
sed -i " s|# ${ option % * } .*| ${ option } | " group_vars/rhcs.yml.sample
done
}
2017-05-15 21:49:45 +08:00
########
# MAIN #
########
for role in " $basedir " /roles/ceph-*; do
rolename = $( basename " $role " )
2017-08-02 16:35:26 +08:00
if [ [ $rolename = = "ceph-defaults" ] ] ; then
2017-08-04 04:37:12 +08:00
output = "all.yml.sample rhcs.yml.sample"
2017-05-15 21:49:45 +08:00
elif [ [ $rolename = = "ceph-fetch-keys" ] ] ; then
output = "ceph-fetch-keys.yml.sample"
2018-06-06 14:41:46 +08:00
elif [ [ $rolename = = "ceph-rbd-mirror" ] ] ; then
output = "rbdmirrors.yml.sample"
2019-04-04 10:54:41 +08:00
elif [ [ $rolename = = "ceph-rgw-loadbalancer" ] ] ; then
output = "rgwloadbalancers.yml.sample"
2017-05-15 21:49:45 +08:00
else
output = " ${ rolename : 5 } s.yml.sample "
fi
defaults = " $role " /defaults/main.yml
if [ [ ! -f $defaults ] ] ; then
continue
fi
2017-08-02 16:35:26 +08:00
if ! echo " $rolename " | grep -qE " $do_not_generate " ; then
populate_header
generate_group_vars_file
fi
2016-02-29 23:35:07 +08:00
done
2017-08-04 04:37:12 +08:00
rhcs_edits