From 62ebbcf86b038fd01891a154c203f58ad434d89e Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 26 May 2018 16:26:33 -0300 Subject: Nodes: ansible support --- share/hydra/nodes | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'share/hydra') diff --git a/share/hydra/nodes b/share/hydra/nodes index eb661c3..fff3549 100755 --- a/share/hydra/nodes +++ b/share/hydra/nodes @@ -17,15 +17,15 @@ # . # 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 -- cgit v1.2.3