aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-05-24 11:23:51 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-05-24 11:23:51 -0300
commit37d3e5c6463e2b62e34ed06de3b371f5614e7376 (patch)
tree0502d81caa55292a85a3e1b378eab75c7f48e4d0 /lib
parentcabfc47ca80492033e3d0eee66e8445119a99d63 (diff)
downloadhydra-37d3e5c6463e2b62e34ed06de3b371f5614e7376.tar.gz
hydra-37d3e5c6463e2b62e34ed06de3b371f5614e7376.tar.bz2
Adds hydra_hiera_query
Diffstat (limited to 'lib')
-rw-r--r--lib/hydra/misc33
1 files changed, 32 insertions, 1 deletions
diff --git a/lib/hydra/misc b/lib/hydra/misc
index 583e43d..77c2988 100644
--- a/lib/hydra/misc
+++ b/lib/hydra/misc
@@ -2,7 +2,7 @@
# Set needed environment variables and do basic checks
function hydra_set_env {
- export BASEREPOS="config doc bootless dns git/public git/private puppet"
+ export BASEREPOS="config doc bootless dns git/public git/private puppet ansible"
export OSVERSION="`cut -d . -f 1 /etc/debian_version`"
export COMMIT="`( cd $APP_BASE && git log -n 1 --pretty=oneline 2> /dev/null | cut -d " " -f 1 )`"
export CONFIG="$HOME/.hydra/config"
@@ -170,3 +170,34 @@ function hydra_get_fqdn_from_nodename {
echo $node.$domain
fi
}
+
+function hydra_hiera_query {
+ local node="$1"
+ local param="$2"
+
+ # Build basic query command
+ hiera="hiera --config $HYDRA_FOLDER/puppet/hiera.yaml"
+ hiera_params="settings::confdir=$HYDRA_FOLDER/puppet ::clientcert=$node"
+ role="`$hiera nodo::role $hiera_params 2> /dev/null`"
+ location="`$hiera nodo::location $hiera_params 2> /dev/null`"
+ virtual="$(grep "^virtual: " $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
+ domain="$(grep "^domain: " $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')"
+
+ if [ ! -z "$virtual" ]; then
+ hiera_params="$hiera_params ::virtual=$virtual"
+ fi
+
+ if [ ! -z "$role" ]; then
+ hiera_params="$hiera_params ::nodo::role=$role"
+ fi
+
+ if [ ! -z "$location" ]; then
+ hiera_params="$hiera_params ::nodo::location=$location"
+ fi
+
+ if [ ! -z "$domain" ]; then
+ hiera_params="$hiera_params ::domain=$domain"
+ fi
+
+ $hiera $param $hiera_params 2> /dev/null
+}