From 37d3e5c6463e2b62e34ed06de3b371f5614e7376 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 24 May 2018 11:23:51 -0300 Subject: Adds hydra_hiera_query --- lib/hydra/misc | 33 ++++++++++++++++++++++++++++++++- share/hydra/compile | 40 ++++++++-------------------------------- 2 files changed, 40 insertions(+), 33 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 +} diff --git a/share/hydra/compile b/share/hydra/compile index 567a78f..6d84c53 100755 --- a/share/hydra/compile +++ b/share/hydra/compile @@ -56,32 +56,8 @@ for node in $NODES; do sshed25519key="$(grep sshed25519key: $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')" sshecdsakey="$(grep sshecdsakey: $FACTS/${node}.yaml | cut -d ':' -f 2 | sed -e 's/ //g' -e 's/"//g')" - # Determine host aliases depending on sshd::ports config host_aliases="" - 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 - - ssh_ports="`$hiera sshd::ports $hiera_params 2> /dev/null`" + ssh_ports="`hydra_hiera_query $node sshd::ports`" if [ "$ssh_ports" != "nil" ] && [ ! -z "$ssh_ports" ]; then ssh_ports="`echo $ssh_ports | sed -e 's/\[//g' -e 's/\]//g' -e 's/,//g'`" @@ -96,15 +72,15 @@ for node in $NODES; do fi if [ ! -z "$rsakey" ]; then - #echo " $node-rsa:" >> $CONFIG - echo " $node:" >> $CONFIG - #echo " name : '$node'" >> $CONFIG - echo " ensure: 'present'" >> $CONFIG - echo " type : 'ssh-rsa'" >> $CONFIG - echo " key : '$rsakey'" >> $CONFIG + #echo " $node-rsa:" >> $CONFIG + echo " $node:" >> $CONFIG + #echo " name : '$node'" >> $CONFIG + echo " ensure : 'present'" >> $CONFIG + echo " type : 'ssh-rsa'" >> $CONFIG + echo " key : '$rsakey'" >> $CONFIG if [ ! -z "$host_aliases" ]; then - echo " host_aliases : [ $host_aliases ]" >> $CONFIG + echo " host_aliases : [ $host_aliases ]" >> $CONFIG fi fi -- cgit v1.2.3