]> gitweb.fluxo.info Git - hydra.git/commitdiff
Feat: deploy: setup custom facts
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 8 May 2020 00:41:39 +0000 (21:41 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 8 May 2020 00:41:39 +0000 (21:41 -0300)
lib/hydra/deploy
share/hydra/deploy

index 497f03a02e5f606a42617d15f9376ee77c84e9dd..b985aa8ae1e4e87a7ad9fd99051c75a9c642bd1b 100644 (file)
@@ -130,7 +130,8 @@ function hydra_yaml_param {
   local param="$1"
   local file="$2"
 
-  grep "^$param: " $file | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'
+  #grep "^$param: " $file | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'
+  grep "^$param" $file | sed -e "s/^$param//" | cut -d ':' -f 2 | sed -e "s/'//g" -e 's/"//g' -e "s/ //g" 
 }
 
 # Create puppet folder structure
@@ -240,6 +241,41 @@ function hydra_deploy_copy {
   fi
 }
 
+# Setup custom facts
+function hydra_deploy_facts_setup {
+  echo "Setting up custom facts..."
+
+  ROLE="`hydra_yaml_param nodo::role $HYDRA_FOLDER/puppet/config/node/$FQDN.yaml`"
+  LOCATION="`hydra_yaml_param nodo::location $HYDRA_FOLDER/puppet/config/node/$FQDN.yaml`"
+
+  if [ -z "$ROLE" ]; then
+    ROLE="default"
+  fi
+
+  if [ -z "$LOCATION" ]; then
+    LOCATION="default"
+  fi
+
+  if [ "$1" == "local" ]; then
+    $SUDO mkdir -p /etc/facter/facts.d
+    $SUDO echo "role=$ROLE"         | $SUDO tee /etc/facter/facts.d/role.txt     > /dev/null
+    $SUDO echo "location=$LOCATION" | $SUDO tee /etc/facter/facts.d/location.txt > /dev/null
+  elif [ "$1" == "remote" ]; then
+    local error
+
+    $HYDRA_CONNECT $FQDN "sudo mkdir -p /etc/facter/facts.d"                                               || error=1
+    $HYDRA_CONNECT $FQDN "echo role=$ROLE         | sudo tee /etc/facter/facts.d/role.txt     > /dev/null" || error=1
+    $HYDRA_CONNECT $FQDN "echo location=$LOCATION | sudo tee /etc/facter/facts.d/location.txt > /dev/null" || error=1
+
+    # Check result
+    #if [ "$?" != "0" ]; then
+    if [ "$error" == "1" ]; then
+      echo "Error setting up facts at $FQDN."
+      return 1
+    fi
+  fi
+}
+
 # Collects facts from a system
 function hydra_deploy_facts_collect {
   echo "Collecting facts from system..."
index 7b9e05e46b80b0e6e945f49e74cadc658ce9d06a..af3d0a2bd82f969e779c55dca6e1fa4b25371c2c 100755 (executable)
@@ -140,6 +140,7 @@ for node in $NODES; do
     hydractl install
 
     # Collect facts
+    hydra_deploy_facts_setup   local
     hydra_deploy_facts_collect local
 
     # Run puppet
@@ -218,6 +219,7 @@ EOF
     hydra_deploy_mkdirs
 
     # Collect facts
+    hydra_deploy_facts_setup   remote || continue
     hydra_deploy_facts_collect remote || continue
 
     # Sync repository to server