Skip to content

Instantly share code, notes, and snippets.

@lusis
Created October 18, 2015 06:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusis/fcb6e50c3d10ededef77 to your computer and use it in GitHub Desktop.
Save lusis/fcb6e50c3d10ededef77 to your computer and use it in GitHub Desktop.
rundeck executor and copy scripts to access nodes behind nat in VPC
#!/bin/bash
# This script requires the following settings
# node attributes:
# file-copier: script-copy
# destdir: /tmp
# project properties:
# plugin.script-copy.default.command=/data/rundeck_scripts/gateway-copier.sh ${node.ssh-keypath} ${node.jumpNode_user} ${node.jumpNode} ${node.username} ${node.hostname} ${file-copy.destination} ${file-copy.file}
# plugin.script-copy.default.remote-filepath=${node.destdir}/${file-copy.filename}
KEYPATH=$1
shift
JUMPUSER=$1
shift
JUMPHOST=$1
shift
REALUSER=$1
shift
REALHOST=$1
shift
DESTFILE=$1
shift
JOBFILE=$1
COMMON_SSHOPTS="-q -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null"
exec scp -i $KEYPATH \
-o "ProxyCommand ssh ${COMMON_SSHOPTS} -W %h:%p -i ${KEYPATH} $JUMPUSER@$JUMPHOST" \
${COMMON_SSHOPTS} \
$JOBFILE ${REALUSER}@${REALHOST}:${DESTFILE}
#!/bin/bash
# This script requires the following settings
# node attributes:
# node-executor: script-exec
# jumpNode: <nat instance ip>
# jumpNode_user: admin
# ssh-keypath: /path/to/common/keyfile
# project properties:
# plugin.script-exec.default.command=/data/rundeck_scripts/gateway-runner.sh ${node.ssh-keypath} ${node.jumpNode_user} ${node.jumpNode} ${node.username} ${node.hostname} -- ${exec.command}
KEYPATH=$1
shift
JUMPUSER=$1
shift
JUMPHOST=$1
shift
REALUSER=$1
shift
REALHOST=$1
shift
DASH=$1
shift
COMMAND=$@
echo "${COMMAND}" > /tmp/$REALHOST.log
COMMON_SSHOPTS="-q -a -T -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null"
exec ssh -i \
$KEYPATH \
-o "ProxyCommand ssh ${COMMON_SSHOPTS} -W %h:%p -i ${KEYPATH} $JUMPUSER@$JUMPHOST" \
${COMMON_SSHOPTS} \
${REALUSER}@${REALHOST} \
"${COMMAND}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment