]> gitweb.fluxo.info Git - hydra.git/commitdiff
Nodes: ansible support
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 26 May 2018 19:26:33 +0000 (16:26 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 26 May 2018 19:26:33 +0000 (16:26 -0300)
share/hydra/nodes

index eb661c3c1714d66f24fe3d1648b4bbe308f5d7ce..fff3549cb4be2b950ec679f535a9096647d7cff5 100755 (executable)
 # <http://www.gnu.org/licenses/>.
 
 # Get a list of puppet node files
-function hydra_node_files {
+function hydra_node_files_puppet {
   if [ -d "$PUPPET/config/node/" ]; then
     #FILES="$PUPPET/config/node/*"
     FILES="`ls -1 $PUPPET/config/node/ | grep -v example.org | xargs`"
   fi
 }
 
-# Return node names
-function hydra_nodes {
+# Return node names from puppet config
+function hydra_nodes_puppet {
   for file in $FILES; do
     basename $file .yaml
   done
@@ -39,23 +39,29 @@ hydra_config_load
 CLASS="$1"
 
 # Validation
-if [ -z "$PUPPET" ]; then
-  echo "No PUPPET parameter defined at $HYDRA preferences."
-  exit 1
-fi
+if ! [ -z "$PUPPET" ]; then
+  # Get initial file list
+  hydra_node_files_puppet
 
-# Get initial file list
-hydra_node_files
+  # Get nodes
+  if [ ! -z "$CLASS" ]; then
+    hydra_nodes_puppet | while read node; do
+      find $PUPPET/config -name "$node.yaml"
+    done | while read candidate; do
+      if grep -e "$CLASS" $candidate | grep -qe "^nodo::role"; then
+        basename $candidate .yaml
+      fi
+    done
+  else
+    hydra_nodes_puppet
+  fi
+elif [ -d "$HYDRA_FOLDER/ansible" ]; then
+  if [ -z "$CLASS" ]; then
+    CLASS="all"
+  fi
 
-# Get nodes
-if [ ! -z "$CLASS" ]; then
-  hydra_nodes | while read node; do
-    find $PUPPET/config -name "$node.yaml"
-  done | while read candidate; do
-    if grep -e "$CLASS" $candidate | grep -qe "^nodo::role"; then
-      basename $candidate .yaml
-    fi
-  done
+  ANSIBLE_CONFIG=$HYDRA_FOLDER/ansible/ansible.cfg ansible -i inventories $CLASS --list-hosts | grep -v "^  hosts (" | sed -e 's/^    //'
 else
-  hydra_nodes
+  echo "No PUPPET parameter defined at $HYDRA preferences or ansible config available."
+  exit 1
 fi