From dde08fea041728a17a090d9a884d446bc0891cd6 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 27 May 2018 12:58:11 -0300 Subject: Deploy: ansible support --- share/hydra/deploy | 35 ++++++++++++++++++++++++++++++++++- share/hydra/nodes | 4 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) (limited to 'share/hydra') diff --git a/share/hydra/deploy b/share/hydra/deploy index 015f81a..ce8b148 100755 --- a/share/hydra/deploy +++ b/share/hydra/deploy @@ -55,7 +55,9 @@ hydra_install_package ansible rsync #echo ' \/\/ \/ \/ \/ \/|__| \/ \/' #echo '' -# Deploy +# +# Deploy iterating over each node +# for node in $NODES; do if [ -d "$node" ]; then echo "Deploying to $node folder..." @@ -232,3 +234,34 @@ EOF fi fi done + +# +# Deploy using ansible own iterator +# + +# Command line arguments +NODES="$*" + +# Build node list +#if [ -z "$NODES" ]; then +# #NODES="`BACKEND=ansible hydra $HYDRA nodes | xargs | sed -e "s/^/'~(/" -e "s/ /|/g" -e "s/$/)'/`" +# NODES="all" +#else +if [ ! -z "$NODES" ]; then + # Check if first param is a node name, otherwise assume its a class + if [ -z "$2" ]; then + NODES="`BACKEND=ansible hydra $HYDRA nodes $1`" + + if [ -z "$NODES" ]; then + NODES="`BACKEND=ansible hydra $HYDRA nodes $1'*'`" + fi + + # It's a class + if [ ! -z "$NODES" ] && [ "`echo $NODES | wc -w`" != "1" ]; then + #NODES="`echo $NODES | xargs | sed -e "s/^/'~(/" -e "s/ /|/g" -e "s/$/)'/"`" + NODES="$*" + fi + fi +fi + +hydra $HYDRA ansible-playbook site.yml --limit $NODES diff --git a/share/hydra/nodes b/share/hydra/nodes index c75d5d3..21a9ad4 100755 --- a/share/hydra/nodes +++ b/share/hydra/nodes @@ -56,7 +56,7 @@ function hydra_nodes_ansible { CLASS="all" fi - hydra $HYDRA ansible $CLASS --list-hosts | grep -v "^ hosts (" | sed -e 's/^ //' + hydra $HYDRA ansible $CLASS --list-hosts 2> /dev/null | grep -v "^ hosts (" | sed -e 's/^ //' } # Load @@ -66,7 +66,7 @@ hydra_config_load # Command line arguments CLASS="$1" -# Validation +# Dispatch if ! [ -z "$PUPPET" ] && [ "$BACKEND" != "ansible" ]; then hydra_nodes_puppet elif [ -d "$HYDRA_FOLDER/ansible" ]; then -- cgit v1.2.3