aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-05-27 12:58:11 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-05-27 12:58:11 -0300
commitdde08fea041728a17a090d9a884d446bc0891cd6 (patch)
treeb122a565403b9514145f0df5ceac28950950b631
parente32b5413c06c3c5d71f374a646e2c07c37b0ef09 (diff)
downloadhydra-dde08fea041728a17a090d9a884d446bc0891cd6.tar.gz
hydra-dde08fea041728a17a090d9a884d446bc0891cd6.tar.bz2
Deploy: ansible support
-rw-r--r--TODO.md4
-rw-r--r--share/ansible/inventories/production/.empty0
-rwxr-xr-xshare/hydra/deploy35
-rwxr-xr-xshare/hydra/nodes4
4 files changed, 37 insertions, 6 deletions
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
--- /dev/null
+++ b/share/ansible/inventories/production/.empty
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