]> gitweb.fluxo.info Git - hydra.git/commitdiff
Adds hydra_hiera_query
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 24 May 2018 14:23:51 +0000 (11:23 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 24 May 2018 14:23:51 +0000 (11:23 -0300)
lib/hydra/misc
share/hydra/compile

index 583e43d30eca5b929223d11205aff1822bfb19ac..77c2988b438179d35c23687b8f291c19108e21d4 100644 (file)
@@ -2,7 +2,7 @@
 
 # Set needed environment variables and do basic checks
 function hydra_set_env {
-  export BASEREPOS="config doc bootless dns git/public git/private puppet"
+  export BASEREPOS="config doc bootless dns git/public git/private puppet ansible"
   export OSVERSION="`cut -d . -f 1 /etc/debian_version`"
   export COMMIT="`( cd $APP_BASE && git log -n 1 --pretty=oneline 2> /dev/null | cut -d " " -f 1 )`"
   export CONFIG="$HOME/.hydra/config"
@@ -170,3 +170,34 @@ function hydra_get_fqdn_from_nodename {
     echo $node.$domain
   fi
 }
+
+function hydra_hiera_query {
+  local node="$1"
+  local param="$2"
+
+  # Build basic query command
+  hiera="hiera --config $HYDRA_FOLDER/puppet/hiera.yaml"
+  hiera_params="settings::confdir=$HYDRA_FOLDER/puppet ::clientcert=$node"
+  role="`$hiera nodo::role $hiera_params 2> /dev/null`"
+  location="`$hiera nodo::location $hiera_params 2> /dev/null`"
+  virtual="$(grep "^virtual: " $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
+  domain="$(grep "^domain: " $FACTS/${node}.yaml   | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
+
+  if [ ! -z "$virtual" ]; then
+    hiera_params="$hiera_params ::virtual=$virtual"
+  fi
+
+  if [ ! -z "$role" ]; then
+    hiera_params="$hiera_params ::nodo::role=$role"
+  fi
+
+  if [ ! -z "$location" ]; then
+    hiera_params="$hiera_params ::nodo::location=$location"
+  fi
+
+  if [ ! -z "$domain" ]; then
+    hiera_params="$hiera_params ::domain=$domain"
+  fi
+
+  $hiera $param $hiera_params 2> /dev/null
+}
index 567a78f2f21fea1978f11589bdad4832aae42ccd..6d84c531fddc605a9d791a92c38fb7e14d2004f8 100755 (executable)
@@ -56,32 +56,8 @@ for node in $NODES; do
     sshed25519key="$(grep sshed25519key: $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
     sshecdsakey="$(grep sshecdsakey: $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
 
-    # Determine host aliases depending on sshd::ports config
     host_aliases=""
-    hiera="hiera --config $HYDRA_FOLDER/puppet/hiera.yaml"
-    hiera_params="settings::confdir=$HYDRA_FOLDER/puppet ::clientcert=$node"
-    role="`$hiera nodo::role $hiera_params 2> /dev/null`"
-    location="`$hiera nodo::location $hiera_params 2> /dev/null`"
-    virtual="$(grep "^virtual: " $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
-    domain="$(grep "^domain: " $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
-
-    if [ ! -z "$virtual" ]; then
-      hiera_params="$hiera_params ::virtual=$virtual"
-    fi
-
-    if [ ! -z "$role" ]; then
-      hiera_params="$hiera_params ::nodo::role=$role"
-    fi
-
-    if [ ! -z "$location" ]; then
-      hiera_params="$hiera_params ::nodo::location=$location"
-    fi
-
-    if [ ! -z "$domain" ]; then
-      hiera_params="$hiera_params ::domain=$domain"
-    fi
-
-    ssh_ports="`$hiera sshd::ports $hiera_params 2> /dev/null`"
+    ssh_ports="`hydra_hiera_query $node sshd::ports`"
 
     if [ "$ssh_ports" != "nil" ] && [ ! -z "$ssh_ports" ]; then
       ssh_ports="`echo $ssh_ports | sed -e 's/\[//g' -e 's/\]//g' -e 's/,//g'`"
@@ -96,15 +72,15 @@ for node in $NODES; do
     fi
 
     if [ ! -z "$rsakey" ]; then
-      #echo "  $node-rsa:"                      >> $CONFIG
-      echo "  $node:"                          >> $CONFIG
-      #echo "    name  : '$node'"               >> $CONFIG
-      echo "    ensure: 'present'"             >> $CONFIG
-      echo "    type  : 'ssh-rsa'"             >> $CONFIG
-      echo "    key   : '$rsakey'"             >> $CONFIG
+      #echo "  $node-rsa:"                 >> $CONFIG
+      echo "  $node:"                      >> $CONFIG
+      #echo "   name         : '$node'"    >> $CONFIG
+      echo "    ensure       : 'present'"  >> $CONFIG
+      echo "    type         : 'ssh-rsa'"  >> $CONFIG
+      echo "    key          : '$rsakey'"  >> $CONFIG
 
       if [ ! -z "$host_aliases" ]; then
-        echo "    host_aliases   : [ $host_aliases ]"             >> $CONFIG
+        echo "    host_aliases : [ $host_aliases ]" >> $CONFIG
       fi
     fi