From 7017d1dad0c88844d35ac8ff2b7735d6ea9e4f34 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 27 May 2018 12:23:32 -0300 Subject: Nodes: support for chosing node config backend between puppet and ansible --- share/hydra/nodes | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'share/hydra') diff --git a/share/hydra/nodes b/share/hydra/nodes index fff3549..c75d5d3 100755 --- a/share/hydra/nodes +++ b/share/hydra/nodes @@ -17,7 +17,7 @@ # . # 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 -- cgit v1.2.3