diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2020-05-07 21:41:39 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2020-05-07 21:41:39 -0300 |
commit | 45fbbd0799fa06cab083207fcb7fbd433d41f6a1 (patch) | |
tree | e179e3f9da69f225a74ca87a8f7a7e7370bf02cf /lib | |
parent | c855d0682aac874fbb64c5cf87e8f3f54ee1aa61 (diff) | |
download | hydra-45fbbd0799fa06cab083207fcb7fbd433d41f6a1.tar.gz hydra-45fbbd0799fa06cab083207fcb7fbd433d41f6a1.tar.bz2 |
Feat: deploy: setup custom facts
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hydra/deploy | 38 |
1 files changed, 37 insertions, 1 deletions
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..." |