]> gitweb.fluxo.info Git - hydra.git/commitdiff
Nodes: support for chosing node config backend between puppet and ansible
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 27 May 2018 15:23:32 +0000 (12:23 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 27 May 2018 15:23:32 +0000 (12:23 -0300)
share/hydra/nodes

index fff3549cb4be2b950ec679f535a9096647d7cff5..c75d5d31c9031ec3f519b5dd6c8f1317ac87a065 100755 (executable)
@@ -17,7 +17,7 @@
 # <http://www.gnu.org/licenses/>.
 
 # Get a list of puppet node files
-function hydra_node_files_puppet {
+function hydra_node_puppet_files {
   if [ -d "$PUPPET/config/node/" ]; then
     #FILES="$PUPPET/config/node/*"
     FILES="`ls -1 $PUPPET/config/node/ | grep -v example.org | xargs`"
@@ -25,27 +25,20 @@ function hydra_node_files_puppet {
 }
 
 # Return node names from puppet config
-function hydra_nodes_puppet {
+function hydra_nodes_puppet_names {
   for file in $FILES; do
     basename $file .yaml
   done
 }
 
-# Load
-source $APP_BASE/lib/hydra/functions || exit 1
-hydra_config_load
-
-# Command line arguments
-CLASS="$1"
-
-# Validation
-if ! [ -z "$PUPPET" ]; then
+# Return nodes from puppet config
+function hydra_nodes_puppet {
   # Get initial file list
-  hydra_node_files_puppet
+  hydra_node_puppet_files
 
   # Get nodes
   if [ ! -z "$CLASS" ]; then
-    hydra_nodes_puppet | while read node; do
+    hydra_nodes_puppet_names | 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
@@ -53,14 +46,31 @@ if ! [ -z "$PUPPET" ]; then
       fi
     done
   else
-    hydra_nodes_puppet
+    hydra_nodes_puppet_names
   fi
-elif [ -d "$HYDRA_FOLDER/ansible" ]; then
+}
+
+# Return nodes from ansible config
+function hydra_nodes_ansible {
   if [ -z "$CLASS" ]; then
     CLASS="all"
   fi
 
-  ANSIBLE_CONFIG=$HYDRA_FOLDER/ansible/ansible.cfg ansible -i inventories $CLASS --list-hosts | grep -v "^  hosts (" | sed -e 's/^    //'
+  hydra $HYDRA ansible $CLASS --list-hosts | grep -v "^  hosts (" | sed -e 's/^    //'
+}
+
+# Load
+source $APP_BASE/lib/hydra/functions || exit 1
+hydra_config_load
+
+# Command line arguments
+CLASS="$1"
+
+# Validation
+if ! [ -z "$PUPPET" ] && [ "$BACKEND" != "ansible" ]; then
+  hydra_nodes_puppet
+elif [ -d "$HYDRA_FOLDER/ansible" ]; then
+  hydra_nodes_ansible
 else
   echo "No PUPPET parameter defined at $HYDRA preferences or ansible config available."
   exit 1