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 --- TODO.md | 4 +--- share/ansible/inventories/production/.empty | 0 share/hydra/deploy | 35 ++++++++++++++++++++++++++++- share/hydra/nodes | 4 ++-- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 share/ansible/inventories/production/.empty diff --git a/TODO.md b/TODO.md index cce4e41..919d872 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,4 @@ TODO * hydractl * sync-tpc: way to ignore /var/cache/qemu and other files from syncing, - perhaps a .sync-tpc-ignore. -* hydra: - * deploy: ansible support + perhaps a .sync-tpc-ignore at the destination. diff --git a/share/ansible/inventories/production/.empty b/share/ansible/inventories/production/.empty new file mode 100644 index 0000000..e69de29 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