Last active
December 3, 2015 21:27
-
-
Save hh/2c5f1f9c33ba9c54e133 to your computer and use it in GitHub Desktop.
creds and winrm and rdp using fingerprints from ec2 via chef-provisoning-aws
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ./bin/creds | |
#!/usr/bin/env bash | |
#JSON=$(knife node show $* -a chef_provisioning.reference -Fjson) | |
#eval $(echo $JSON | jq -r '.[]["chef_provisioning.reference"]' |grep -Ev '{|}' |sed 's/\s*"\([^"]*\)": /\1=/') | |
# sets winrm_ssl_thumbprintprint and others at that level | |
# use this later | |
export NODE_NAME="$*" | |
INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=$NODE_NAME" | jq .Reservations[0].Instances[0].InstanceId | sed -e 's/\"//g') | |
FINGERPRINT=$(aws ec2 get-console-output --instance-id $INSTANCE_ID | jq -r '.Output' | grep RDPCERTIFICATE-THUMBPRINT | tail -1 | awk '{print $4}') | |
export FINGERPRINT=${FINGERPRINT//[$'\t\r\n ']} # get rid of newlines etc | |
export IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | grep PrivateIpAddress |tail -1 | awk -F '"' '{print $4}') | |
export PASSWORD=$(aws ec2 get-password-data --instance-id $INSTANCE_ID --priv-launch-key $HOME/.chef/keys/chef_default | grep PasswordData | awk -F '"' '{print $4}') | |
echo export NODE_NAME="$NODE_NAME" | |
echo export PASSWORD=\"$PASSWORD\" | |
echo export IP="$IP" | |
echo export INSTANCE_ID="$INSTANCE_ID" | |
echo export FINGERPRINT="$FINGERPRINT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
current_dir = File.dirname(__FILE__) | |
if ENV['PASSWORD'] | |
knife[:winrm_password] = ENV['PASSWORD'] | |
end | |
if ['FINGERPRINT'] | |
knife[:ssl_peer_fingerprint] = ENV['FINGERPRINT'] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$NODE_NAME" != "$1" ] | |
then | |
NODE_NAME=$* | |
echo Retrieving instance id and ip address and password for $NODE_NAME | |
CREDS="$( dirname "${BASH_SOURCE[0]}" )/creds" | |
eval $($CREDS $NODE_NAME) | |
else | |
echo Using cached instance id and ip address and password for $NODE_NAME | |
fi | |
killall rdesktop | |
#rdesktop -g 1100x740 -u Administrator -p "${PASSWORD}" -r sound:local -r disk:prov=`pwd` $IP & | |
rdesktop -g 1100x1240 -u Administrator -p "${PASSWORD}" -r sound:local -r disk:prov=`pwd` $IP & | |
# would be nice to poll the above output for 'connected' | |
echo "Wait for a connection" | |
sleep 5.0 | |
echo "Focus on RDP Client" | |
xdotool search -name rdesktop windowactivate | |
echo "Get rid of security notice" | |
xdotool key Return | |
echo "Wait for password field" | |
sleep 0.25 | |
echo "Move to password field" | |
xdotool key Tab | |
sleep 0.25 | |
echo "Type password" | |
xdotool type "$PASSWORD" | |
sleep 0.25 | |
echo "Login!" | |
xdotool key Return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$NODE_NAME" != "$1" ] | |
then | |
NODE_NAME=$1 | |
CREDS="$( dirname "${BASH_SOURCE[0]}" )/creds" | |
echo Retrieving instance id and ip address and password for $NODE_NAME | |
echo Cache by running \'eval \$\("$CREDS $NODE_NAME"\)\' before hand | |
eval $($CREDS $NODE_NAME) | |
else | |
echo Using cached instance id and ip address and password for $NODE_NAME | |
fi | |
shift | |
ARGS="$*" | |
#echo $ARGS | |
#echo "knife winrm --winrm-password 'PASSWORD' -m $IP '$ARGS'" | |
knife winrm --winrm-password "$PASSWORD" -m $IP "$*" | sed -e "s:$IP ::" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment