From d33c4fa00732dc024dc7f28a986891507c544e3f Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 25 Sep 2015 20:24:03 -0300 Subject: Deploy: custom facts and YAML --- share/hydractl/deploy | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'share/hydractl') diff --git a/share/hydractl/deploy b/share/hydractl/deploy index 7bedb1e..3e6c7d2 100755 --- a/share/hydractl/deploy +++ b/share/hydractl/deploy @@ -21,8 +21,8 @@ source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load # Parameters -MANIFEST="`facter fqdn`.pp" FOLDER="$1" +FQDN="`facter fqdn`" # Set sudo config local sudo device rsync @@ -37,6 +37,11 @@ if [ ! -z "$FOLDER" ]; then exit 1 fi + # Fix hostname + if [ -s "$FOLDER/etc/hostname" ]; then + FQDN="`cat $FOLDER/etc/hostname`" + fi + echo "Deploying to $FOLDER..." # Saner defaults @@ -46,12 +51,37 @@ if [ ! -z "$FOLDER" ]; then # Sync repository to server # Exclude eventual keys and version control files - $sudo rsync -CrltDv --no-perms --exclude=keys --delete $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/ + $sudo rsync -CrltDv --no-perms --exclude=keys --exclude=hiera --delete $HYDRA_FOLDER/puppet/ $FOLDER/etc/puppet/ + + # Setup custom facts + DOMAIN="`echo $FQDN | cut -d . -f 2-`" + ROLE="`grep "^nodo::role: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`" + LOCATION="`grep "^nodo::location: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`" + + # Copy needed hiera YAMLs + $sudo mkdir -p $FOLDER/etc/puppet/{domain,location,node,role,virtual} + $sudo cp $HYDRA_FOLDER/puppet/hiera/domain/$DOMAIN.yaml $FOLDER/etc/puppet/hiera/domain/ + $sudo cp $HYDRA_FOLDER/puppet/hiera/location/$LOCATION.yaml $FOLDER/etc/puppet/hiera/location/ + $sudo cp $HYDRA_FOLDER/puppet/hiera/location/$ROLE.yaml $FOLDER/etc/puppet/hiera/role/ + $sudo rsync -av --delete $HYDRA_FOLDER/puppet/hiera/virtual/ $FOLDER/etc/puppet/hiera/virtual/ + + # Check for manifest + if [ ! -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then + echo "Not found: $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" + exit 1 + fi # Run puppet - $sudo chroot $FOLDER puppet apply /etc/puppet/manifests/nodes/$MANIFEST -elif [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/$MANIFEST" ]; then + LC_ALL=C FACTER_role=$ROLE FACTER_location=$LOCATION \ + $sudo chroot $FOLDER puppet apply /etc/puppet/manifests/nodes/$FQDN.pp +elif [ -e "$HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp" ]; then + # Setup custom facts + DOMAIN="`echo $FQDN | cut -d . -f 2-`" + ROLE="`grep "^nodo::role: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`" + LOCATION="`grep "^nodo::location: " domain/$DOMAIN/$FQDN.yaml | cut -d ' ' -f 2 | sed -e "s/'//g" -e 's/"//g'`" + # Run puppet - $sudo puppet apply --confdir=$HYDRA_FOLDER/puppet \ - --modulepath=$HYDRA_FOLDER/modules $HYDRA_FOLDER/puppet/manifests/nodes/$MANIFEST + LC_ALL=C FACTER_role=$ROLE FACTER_location=$LOCATION \ + $sudo puppet apply --confdir=$HYDRA_FOLDER/puppet \ + --modulepath=$HYDRA_FOLDER/modules $HYDRA_FOLDER/puppet/manifests/nodes/$FQDN.pp fi -- cgit v1.2.3