From e925984f4e858d5e17b60615e992314cdaf50ba4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 23 May 2018 16:45:09 -0300 Subject: Deploy: import keys if needed --- TODO.md | 1 - share/hydra/deploy | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 4314947..be5e2c2 100644 --- a/TODO.md +++ b/TODO.md @@ -7,4 +7,3 @@ TODO * hydra: * deploy: * manage ansible package at local machine - * check if server needs import-keys, or always import them diff --git a/share/hydra/deploy b/share/hydra/deploy index 32dc700..63ff54e 100755 --- a/share/hydra/deploy +++ b/share/hydra/deploy @@ -84,6 +84,11 @@ for node in $NODES; do echo "Applying configuration..." LC_ALL=C HOSTNAME=$FQDN FACTER_domain=$DOMAIN FACTER_hostname=$FQDN FACTER_fqdn=$HOSTNAME.$DOMAIN $DEPLOY_APPLY 2>&1 | \ tee $HYDRA_FOLDER/puppet/logs/$FQDN.`date +%Y%m%d%H%M`.log + + # Check if keys should be imported + if ! $SUDO test -f $FOLDER/root/.ssh/id_rsa; then + echo "No $FOLDER/root/.ssh/id_rsa found. Please import it and other keys when the system is online using import-keys action" + fi elif [ "$node" == "localhost" ] || [ "$node" == "`facter fqdn`" ] || [ "$node" == "`facter hostname`" ]; then echo "Deploying to localhost..." @@ -118,6 +123,11 @@ for node in $NODES; do # Fix ssl folder ownership $SUDO chown -R `whoami`. $HYDRA_FOLDER/puppet/ssl + + # Import keys if needed + if ! $SUDO test -f /root/.ssh/id_rsa; then + hydra $HYDRA import-keys localhost + fi else echo "Deploying to $node..." @@ -196,5 +206,10 @@ EOF echo "Applying configuration..." $DEPLOY_APPLY 2>&1 | \ tee $HYDRA_FOLDER/puppet/logs/$FQDN.`date +%Y%m%d%H%M`.log + + # Import keys if needed + if ! $HYDRA_CONNECT $FQDN sudo test -f /root/.ssh/id_rsa; then + hydra $HYDRA import-keys localhost + fi fi done -- cgit v1.2.3