From 45fbbd0799fa06cab083207fcb7fbd433d41f6a1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 7 May 2020 21:41:39 -0300 Subject: Feat: deploy: setup custom facts --- lib/hydra/deploy | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/hydra/deploy b/lib/hydra/deploy index 497f03a..b985aa8 100644 --- a/lib/hydra/deploy +++ b/lib/hydra/deploy @@ -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..." -- cgit v1.2.3