]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
generate_group_vars_sample: ability to merge roles
authorSébastien Han <seb@redhat.com>
Mon, 15 May 2017 13:49:45 +0000 (15:49 +0200)
committerSébastien Han <seb@redhat.com>
Mon, 15 May 2017 13:53:47 +0000 (15:53 +0200)
Problem: the meta declaration just includes the role, it does nothing
with the group_vars. For ansible to use files defined in group_vars/ the
name of the file must match a host group. Like mons, osds, etc. There is
no group docker-common so the variables defined there are never used, as
proved by https://bugzilla.redhat.com/show_bug.cgi?id=1447179 and the
ansible documentation.

Solution: bring the ability to merge roles files. So now by default,
ceph-docker-common and ceph-common will go into all.yml.sample

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1447179
Signed-off-by: Sébastien Han <seb@redhat.com>
generate_group_vars_sample.sh

index e42253858297c518802a885155cbfe59f840ab2d..1e7bd07a42323dc43fc42ba156d5e6763162da37 100755 (executable)
@@ -2,20 +2,20 @@
 
 set -euo pipefail
 
+#############
+# VARIABLES #
+#############
+
 basedir=$(dirname "$0")
+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$'
 
-for role in "$basedir"/roles/ceph-*; do
-  rolename=$(basename "$role")
-  if [[ $rolename == "ceph-common" ]]; 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
 
+#############
+# FUNCTIONS #
+#############
+
+populate_header () {
   cat <<EOF > "$basedir"/group_vars/"$output"
 ---
 # Variables here are applicable to all host groups NOT roles
@@ -27,11 +27,9 @@ for role in "$basedir"/roles/ceph-*; do
 dummy:
 
 EOF
-  defaults="$role"/defaults/main.yml
-  if [[ ! -f $defaults ]]; then
-    continue
-  fi
+}
 
+generate_group_vars_file () {
   if [ "$(uname)" == "Darwin" ]; then
     sed '/^---/d; s/^\([A-Za-z[:space:]]\)/#\1/' \
       "$defaults" >> "$basedir"/group_vars/"$output"
@@ -44,4 +42,37 @@ EOF
     echo "Unsupported platform"
     exit 1
   fi
+}
+
+
+########
+# 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
 done