]> gitweb.fluxo.info Git - hydra.git/commitdiff
Deploy: change copy files procedure to workaround bash quoting limitations
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 19 Oct 2015 17:00:06 +0000 (15:00 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 19 Oct 2015 17:00:06 +0000 (15:00 -0200)
lib/hydra/deploy
share/hydra/deploy
share/hydractl/deploy

index 9fdb9e8bcd58396abadc5dfb48e1fb3d83598c68..5fecafdf86acf20d2af34dbe842332a08fa48edf 100644 (file)
@@ -4,17 +4,20 @@
 function hydra_deploy_setup {
   # Common parameters
   # Exclude eventual keys and version control files
-  DEPLOY_RSYNC="rsync -CrltDv --no-perms --exclude=keys --exclude=hiera/secrets --delete"
+  DEPLOY_RSYNC="rsync -CrltDv --no-perms --exclude=ssl --exclude=keys --exclude=hiera/secrets --delete --rsync-path"
+  RSYNC_PATH="rsync"
+  COPY_PATH=""
 
   if [ "$1" == "remote" ]; then
     # Deploy in a local folder
     if [ ! -z "$2" ]; then
       NODE="$2"
       DEPLOY_COMMAND="$HYDRA_CONNECT $NODE sudo"
-      DEPLOY_RSYNC="$DEPLOY_RSYNC --rsync-path 'sudo rsync' $HYDRA_FOLDER/puppet/ $NODE:/etc/puppet/"
+      RSYNC_PATH="sudo rsync"
+      DEPLOY_OPTS="$HYDRA_FOLDER/puppet/ $NODE:/etc/puppet/"
       FQDN="`$DEPLOY_COMMAND facter fqdn`"
       DEPLOY_DEST="$FQDN:"
-      DEPLOY_COPY="$DEPLOY_RSYNC"
+      COPY_PATH="$RSYNC_PATH"
       PUPPET_MANIFEST="/etc/puppet/manifests/nodes/$FQDN.pp"
     else
       echo "No folder specified."
@@ -25,8 +28,7 @@ function hydra_deploy_setup {
     if [ ! -z "$2" ]; then
       FOLDER="$2"
       DEPLOY_COMMAND="$SUDO chroot $FOLDER"
-      DEPLOY_RSYNC="$DEPLOY_RSYNC $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/"
-      DEPLOY_COPY="$SUDO cp"
+      DEPLOY_OPTS="$HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/"
       DEPLOY_DEST="$FOLDER"
       PUPPET_MANIFEST="/etc/puppet/manifests/nodes/$FQDN.pp"
 
@@ -45,6 +47,7 @@ function hydra_deploy_setup {
     fi
   else
     # Deploy on the localhost
+    DEPLOY_RSYNC=""
     DEPLOY_COMMAND="$SUDO"
     FQDN="`facter fqdn`"
     PUPPET_OPTS="--confdir=$HYDRA_FOLDER/puppet --modulepath=$HYDRA_FOLDER/modules"
@@ -81,23 +84,42 @@ function hydra_deploy_mkdirs {
   $DEPLOY_COMMAND chmod -R 640   /etc/puppet
 }
 
-# Create hiera folder structure
-function hydra_hiera_copy {
+# Copy hiera secrets
+function hydra_deploy_copy_secrets {
+  local location="$1"
+
+  if [ -z "$location" ]; then
+    location="remote"
+  fi
+
   $DEPLOY_COMMAND mkdir -p $FOLDER/etc/puppet/secrets/{domain,location,node,role}
 
   if [ ! -z "$DOMAIN" ] && [ -e "$HYDRA_FOLDER/puppet/hiera/secrets/domain/$DOMAIN.yaml" ]; then
-    $DEPLOY_COPY $HYDRA_FOLDER/puppet/hiera/secrets/domain/$DOMAIN.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/domain/
+    hydra_deploy_copy $location $HYDRA_FOLDER/puppet/hiera/secrets/domain/$DOMAIN.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/domain/
   fi
 
   if [ ! -z "$LOCATION" ] && [ -e "$HYDRA_FOLDER/puppet/hiera/secrets/location/$LOCATION.yaml" ]; then
-    $DEPLOY_COPY $HYDRA_FOLDER/puppet/hiera/secrets/location/$LOCATION.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/location/
+    hydra_deploy_copy $location $HYDRA_FOLDER/puppet/hiera/secrets/location/$LOCATION.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/location/
   fi
 
   if [ ! -z "$ROLE" ] && [ -e "$HYDRA_FOLDER/puppet/hiera/secrets/role/$ROLE.yaml" ]; then
-    $DEPLOY_COPY $HYDRA_FOLDER/puppet/hiera/secrets/role/$ROLE.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/role/
+    hydra_deploy_copy $location $HYDRA_FOLDER/puppet/hiera/secrets/role/$ROLE.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/role/
   fi
 
   if [ ! -z "$NODE" ] && [ -e "$HYDRA_FOLDER/puppet/hiera/secrets/node/$NODE.yaml" ]; then
-    $DEPLOY_COPY $HYDRA_FOLDER/puppet/hiera/secrets/node/$NODE.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/node/
+    hydra_deploy_copy $location $HYDRA_FOLDER/puppet/hiera/secrets/node/$NODE.yaml $DEPLOY_DEST/etc/puppet/hiera/secrets/node/
+  fi
+}
+
+# Copy a single file
+function hydra_deploy_copy {
+  local location="$1"
+  local orig="$2"
+  local dest="$3"
+
+  if [ "$location" == "folder" ]; then
+    $SUDO cp $orig $dest
+  elif [ "$location" == "remote" ]; then
+    $DEPLOY_RSYNC "$RSYNC_PATH" $orig $dest
   fi
 }
index 4be5392293ccb533f1b90aba2547e515cd4b1919..d7d4d952cadb4f5239d82530ea5f34ea9821bda1 100755 (executable)
@@ -37,10 +37,10 @@ for node in $NODES; do
   hydra_deploy_mkdirs
 
   # Sync repository to server
-  $DEPLOY_RSYNC
+  $DEPLOY_RSYNC "$RSYNC_PATH" $DEPLOY_OPTS
 
   # Copy hiera configuration
-  hydra_hiera_copy
+  hydra_deploy_copy_secrets remote
 
   # Check if puppet is installed
   $HYDRA_CONNECT $node <<EOF
index 6f9de7c4a8e4d8efe1726e8df0bd6cdbfa439391..a500a6ea1b0d20cfc036296935c44930fd2f0532 100755 (executable)
@@ -28,14 +28,14 @@ if [ ! -z "$FOLDER" ]; then
   echo "Deploying to $FOLDER..."
 
   # Setup deploy environment
-  hydra_deploy_setup remote $node
+  hydra_deploy_setup folder $FOLDER
   hydra_deploy_mkdirs
 
   # Sync repository to server
-  $DEPLOY_RSYNC
+  $DEPLOY_RSYNC "$RSYNC_PATH" $DEPLOY_OPTS
 
   # Copy hiera configuration
-  hydra_hiera_copy
+  hydra_deploy_copy_secrets folder
 
   # Check if puppet is installed
   if [ ! -e "$FOLDER/usr/bin/puppet" ]; then