aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2015-09-25 20:24:03 -0300
committerSilvio Rhatto <rhatto@riseup.net>2015-09-25 20:24:03 -0300
commitd33c4fa00732dc024dc7f28a986891507c544e3f (patch)
tree622c79e2048fae6080caaaa27f75eb62f82a6139
parentc1d209a59cf4f7a70512329de49aff3c6c0cb8dd (diff)
downloadhydra-d33c4fa00732dc024dc7f28a986891507c544e3f.tar.gz
hydra-d33c4fa00732dc024dc7f28a986891507c544e3f.tar.bz2
Deploy: custom facts and YAML
-rwxr-xr-xshare/hydra/deploy20
-rwxr-xr-xshare/hydractl/deploy42
2 files changed, 54 insertions, 8 deletions
diff --git a/share/hydra/deploy b/share/hydra/deploy
index 3705a9e..6b91480 100755
--- a/share/hydra/deploy
+++ b/share/hydra/deploy
@@ -39,14 +39,30 @@ for node in $NODES; do
# Sync repository to server
# Exclude eventual keys and version control files
- rsync -CrltDv --no-perms --exclude=keys --delete --rsync-path "sudo rsync" $HYDRA_FOLDER/puppet/ $node:/etc/puppet/
+ rsync -CrltDv --no-perms --exclude=keys --exclude=hiera --delete --rsync-path "sudo rsync" $HYDRA_FOLDER/puppet/ $node:/etc/puppet/
+
+ # Setup custom facts
+ FQDN="`$HYDRA_CONNECT $node facter fqdn`"
+ DOMAIN="`echo $FQDN | cut -d . -f 2-`"
+ ROLE="`grep "^nodo::role: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+ LOCATION="`grep "^nodo::location: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+
+ # Check for manifest
+ if [ ! -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then
+ echo "Not found: $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp"
+ exit 1
+ fi
+
+ # Copy needed hiera YAMLs
+ # TODO
# Run puppet
$HYDRA_CONNECT $node <<EOF
##### BEGIN REMOTE SCRIPT #####
sudo chown -R root. /etc/puppet
sudo chmod -R 640 /etc/puppet
- sudo puppet apply /etc/puppet/manifests/nodes/\$(facter fqdn).pp
+ LC_ALL=C FACTER_role=$ROLE FACTER_location=$LOCATION \
+ sudo puppet apply /etc/puppet/manifests/nodes/$FQDN.pp
##### END REMOTE SCRIPT #######
EOF
done
diff --git a/share/hydractl/deploy b/share/hydractl/deploy
index 7bedb1e..3e6c7d2 100755
--- a/share/hydractl/deploy
+++ b/share/hydractl/deploy
@@ -21,8 +21,8 @@ source $APP_BASE/lib/hydra/functions || exit 1
hydra_config_load
# Parameters
-MANIFEST="`facter fqdn`.pp"
FOLDER="$1"
+FQDN="`facter fqdn`"
# Set sudo config
local sudo device rsync
@@ -37,6 +37,11 @@ if [ ! -z "$FOLDER" ]; then
exit 1
fi
+ # Fix hostname
+ if [ -s "$FOLDER/etc/hostname" ]; then
+ FQDN="`cat $FOLDER/etc/hostname`"
+ fi
+
echo "Deploying to $FOLDER..."
# Saner defaults
@@ -46,12 +51,37 @@ if [ ! -z "$FOLDER" ]; then
# Sync repository to server
# Exclude eventual keys and version control files
- $sudo rsync -CrltDv --no-perms --exclude=keys --delete $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/
+ $sudo rsync -CrltDv --no-perms --exclude=keys --exclude=hiera --delete $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/
+
+ # Setup custom facts
+ DOMAIN="`echo $FQDN | cut -d . -f 2-`"
+ ROLE="`grep "^nodo::role: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+ LOCATION="`grep "^nodo::location: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+
+ # Copy needed hiera YAMLs
+ $sudo mkdir -p $FOLDER/etc/puppet/{domain,location,node,role,virtual}
+ $sudo cp $HYDRA_FOLDER/puppet/hiera/domain/$DOMAIN.yaml $FOLDER/etc/puppet/hiera/domain/
+ $sudo cp $HYDRA_FOLDER/puppet/hiera/location/$LOCATION.yaml $FOLDER/etc/puppet/hiera/location/
+ $sudo cp $HYDRA_FOLDER/puppet/hiera/location/$ROLE.yaml $FOLDER/etc/puppet/hiera/role/
+ $sudo rsync -av --delete $HYDRA_FOLDER/puppet/hiera/virtual/ $FOLDER/etc/puppet/hiera/virtual/
+
+ # Check for manifest
+ if [ ! -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then
+ echo "Not found: $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp"
+ exit 1
+ fi
# Run puppet
- $sudo chroot $FOLDER puppet apply /etc/puppet/manifests/nodes/$MANIFEST
-elif [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/$MANIFEST" ]; then
+ LC_ALL=C FACTER_role=$ROLE FACTER_location=$LOCATION \
+ $sudo chroot $FOLDER puppet apply /etc/puppet/manifests/nodes/$FQDN.pp
+elif [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then
+ # Setup custom facts
+ DOMAIN="`echo $FQDN | cut -d . -f 2-`"
+ ROLE="`grep "^nodo::role: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+ LOCATION="`grep "^nodo::location: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`"
+
# Run puppet
- $sudo puppet apply --confdir=$HYDRA_FOLDER/puppet \
- --modulepath=$HYDRA_FOLDER/modules $HYDRA_FOLDER/puppet/manifests/nodes/$MANIFEST
+ LC_ALL=C FACTER_role=$ROLE FACTER_location=$LOCATION \
+ $sudo puppet apply --confdir=$HYDRA_FOLDER/puppet \
+ --modulepath=$HYDRA_FOLDER/modules $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp
fi