]> gitweb.fluxo.info Git - hydra.git/commitdiff
Deploy: custom facts and YAML
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 25 Sep 2015 23:24:03 +0000 (20:24 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 25 Sep 2015 23:24:03 +0000 (20:24 -0300)
share/hydra/deploy
share/hydractl/deploy

index 3705a9e23b57bf9d58f23219b126ac5e9adc18a2..6b91480cb4b95b1e62efd2549028e43df42cf19a 100755 (executable)
@@ -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
index 7bedb1e9ee7405ba478cf03a51b598386748bfef..3e6c7d28a4e3bf52a8db7abc44cad409b7769a0d 100755 (executable)
@@ -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