summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hydra/config2
-rw-r--r--lib/hydra/deploy112
-rw-r--r--lib/hydra/misc3
3 files changed, 83 insertions, 34 deletions
diff --git a/lib/hydra/config b/lib/hydra/config
index d1eb411..5390159 100644
--- a/lib/hydra/config
+++ b/lib/hydra/config
@@ -52,7 +52,7 @@ function hydra_check_preferences {
PUPPET="$HYDRA_FOLDER/puppet"
PUPPET_KEYS="$PUPPET/keys"
- export HYDRA_CONNECT="ssh -T -o ConnectTimeout=15"
+ export HYDRA_CONNECT="ssh -T -q -o ConnectTimeout=15"
}
# Load a parameter from config
diff --git a/lib/hydra/deploy b/lib/hydra/deploy
index d5df1a0..771c42e 100644
--- a/lib/hydra/deploy
+++ b/lib/hydra/deploy
@@ -4,63 +4,91 @@
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_DEPENDENCIES="puppet-common ruby-sqlite3 ruby-activerecord ruby-activerecord-deprecated-finders augeas-tools"
+ DEPLOY_RSYNC="rsync -CrltDvpq --no-owner --exclude=/ssl --exclude=keys --exclude=site_keys --exclude=hiera/secrets --delete --rsync-path"
+ RSYNC_PATH="rsync -q"
if [ "$1" == "remote" ]; then
- # Deploy in a local folder
+ # Deploy in a remote host
if [ ! -z "$2" ]; then
NODE="$2"
+ DEPLOY_BASE="/etc"
DEPLOY_COMMAND="$HYDRA_CONNECT $NODE sudo"
- DEPLOY_RSYNC="$DEPLOY_RSYNC --rsync-path \"sudo rsync\" $HYDRA_FOLDER/puppet/ $NODE:/etc/puppet/"
- FQDN="`$DEPLOY_COMMAND facter fqdn`"
+ FQDN="`$DEPLOY_COMMAND cat /etc/hostname`"
+ DEPLOY_OPTS="$HYDRA_FOLDER/puppet/ $NODE:/etc/puppet/"
DEPLOY_DEST="$FQDN:"
- DEPLOY_COPY="$DEPLOY_RSYNC"
- PUPPET_MANIFEST="/etc/puppet/manifests/nodes/$FQDN.pp"
+ RSYNC_PATH="sudo rsync -q"
+ REMOTE_ENV="LC_ALL=C"
+ hydra_deploy_set_manifest
else
echo "No folder specified."
exit 1
fi
elif [ "$1" == "folder" ]; then
- # Deploy in a remote host
+ # Deploy in a local folder
if [ ! -z "$2" ]; then
FOLDER="$2"
+ DEPLOY_BASE="/etc"
DEPLOY_COMMAND="$SUDO chroot $FOLDER"
- DEPLOY_RSYNC="$DEPLOY_RSYNC $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/"
- DEPLOY_COPY="$SUDO cp"
+ DEPLOY_RSYNC="$SUDO $DEPLOY_RSYNC"
+ DEPLOY_OPTS="$HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/"
DEPLOY_DEST="$FOLDER"
- PUPPET_MANIFEST="/etc/puppet/manifests/nodes/$FQDN.pp"
-
- if [ ! -d "$FOLDER"]; then
- echo "folder not found: $FOLDER"
- exit 1
- fi
# Fix hostname
if [ -s "$FOLDER/etc/hostname" ]; then
FQDN="`cat $FOLDER/etc/hostname`"
fi
+
+ hydra_deploy_set_manifest
+
+ if [ ! -d "$FOLDER" ]; then
+ echo "folder not found: $FOLDER"
+ exit 1
+ fi
else
echo "No node specified."
exit 1
fi
else
# Deploy on the localhost
+ DEPLOY_BASE="$HYDRA_FOLDER"
DEPLOY_COMMAND="$SUDO"
- FQDN="`facter fqdn`"
- PUPPET_OPTS="--confdir=$HYDRA_FOLDER/puppet --modulepath=$HYDRA_FOLDER/modules"
- PUPPET_MANIFEST="$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp"
+ DEPLOY_RSYNC=""
+ FQDN="`cat /etc/hostname`"
+ PUPPET_OPTS="--confdir=$HYDRA_FOLDER/puppet --modulepath=$HYDRA_FOLDER/puppet/modules"
+ hydra_deploy_set_manifest $HYDRA_FOLDER
fi
# Common parameters
DOMAIN="`echo $FQDN | cut -d . -f 2-`"
- ROLE="`hydra_yaml_param nodo::role $HYDRA_FOLDER/$DOMAIN/$FQDN.yaml`"
- LOCATION="`hydra_yaml_param nodo::location $HYDRA_FOLDER/$DOMAIN/$FQDN.yaml`"
- DEPLOY_PUPPET="puppet appy $PUPPET_OPTS $PUPPET_MANIFEST"
+ ROLE="`hydra_yaml_param nodo::role $HYDRA_FOLDER/puppet/hiera/node/$FQDN.yaml`"
+ LOCATION="`hydra_yaml_param nodo::location $HYDRA_FOLDER/puppet/hiera/node/$FQDN.yaml`"
+
+ # Puppet command
+ if [ -e "$HYDRA_FOLDER/puppet/bin/deploy" ]; then
+ DEPLOY_PUPPET="$DEPLOY_BASE/puppet/bin/deploy"
+ else
+ DEPLOY_PUPPET="$REMOTE_ENV puppet apply $PUPPET_OPTS $PUPPET_MANIFEST"
+ fi
+
+ # Deployment command
DEPLOY_APPLY="$DEPLOY_COMMAND $DEPLOY_PUPPET"
+}
+
+# Manifest
+function hydra_deploy_set_manifest {
+ local prefix="$1"
- # Check for manifest
- if [ ! -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then
- echo "Not found: $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp"
+ if [ -z "$prefix" ]; then
+ prefix="/etc"
+ fi
+
+ if [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then
+ PUPPET_MANIFEST="$prefix/puppet/manifests/nodes/$FQDN.pp"
+ elif [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/default.pp" ]; then
+ PUPPET_MANIFEST="$prefix/puppet/manifests/nodes/default.pp"
+ else
+ echo "no manifest found for $FQDN"
exit 1
fi
}
@@ -81,23 +109,43 @@ function hydra_deploy_mkdirs {
$DEPLOY_COMMAND chmod -R 640 /etc/puppet
}
-# Create hiera folder structure
-function hydra_hiera_copy {
- $DEPLOY_COMMAND mkdir -p $FOLDER/etc/puppet/secrets/{domain,location,node,role}
+# 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/hiera/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/
+ if [ ! -z "$FQDN" ] && [ -e "$HYDRA_FOLDER/puppet/hiera/secrets/node/$FQDN.yaml" ]; then
+ hydra_deploy_copy $location $HYDRA_FOLDER/puppet/hiera/secrets/node/$FQDN.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 mkdir -p $dest
+ $SUDO cp $orig $dest
+ elif [ "$location" == "remote" ]; then
+ $DEPLOY_RSYNC "$RSYNC_PATH" $orig $dest
fi
}
diff --git a/lib/hydra/misc b/lib/hydra/misc
index 2c44503..d8dfb3b 100644
--- a/lib/hydra/misc
+++ b/lib/hydra/misc
@@ -2,7 +2,8 @@
# Set needed environment variables and do basic checks
function hydra_set_env {
- export COMMIT="`( cd $APP_BASE && git log -n 1 --pretty=oneline | cut -d " " -f 1 )`"
+ export OSVERSION="`cut -d . -f 1 /etc/debian_version`"
+ export COMMIT="`( cd $APP_BASE && git log -n 1 --pretty=oneline 2> /dev/null | cut -d " " -f 1 )`"
export CONFIG="$HOME/.hydra/config"
export ACTION="$1"