]> gitweb.fluxo.info Git - hydra.git/commitdiff
Deploy: ansible support
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 27 May 2018 15:58:11 +0000 (12:58 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 27 May 2018 15:58:11 +0000 (12:58 -0300)
TODO.md
share/ansible/inventories/production/.empty [new file with mode: 0644]
share/hydra/deploy
share/hydra/nodes

diff --git a/TODO.md b/TODO.md
index cce4e41156e3c34772bba4e8c52a874cbe519585..919d8720937f6e54fcbf724384cf8b4913a8ceca 100644 (file)
--- 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 (file)
index 0000000..e69de29
index 015f81a8dcba53da83d4960f9a366cdafd158824..ce8b148de1fdc7c05cd28d514ab6719f5c3b2bd9 100755 (executable)
@@ -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
index c75d5d31c9031ec3f519b5dd6c8f1317ac87a065..21a9ad4c70c4e2576927fdc73775abdfc0491e91 100755 (executable)
@@ -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