Skip to content

Commit 86f2035

Browse files
committed
WAFFLES_SSH_KEY and WAFFLES_SITE_DIR
This commit adds the ability to specify an SSH key for remote deployments. By default, ~/.ssh/id_rsa will be used. This commit also fixes the long-standing issue where WAFFLES_SITE_DIR had to be in WAFFLES_DIR in order for remote deployments.
1 parent d69c90c commit 86f2035

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

docs/usage.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ For the sake of simplicity, we'll call our role `memcached`.
1616

1717
Roles are defined in `site/roles`. `site` is a special directory that will hold the configuration for your _site_ or environment. You most likely wouldn't be able to transfer `site` to a new environment and have it run without some level of modification.
1818

19-
Note: The location of the `site` directory can be changed in `waffles.conf`, but at this time, Waffles requires it to be in the main `waffles` directory.
20-
2119
A role is really just a Bash script, and if you'd prefer to just use Waffles to organize a collection of deployment scripts, go for it.
2220

2321
To use roles most effectively, think of them as glue between _data_ and _profiles_:

waffles.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function help {
1818
echo " -u: (push) the remote user to connect as through SSH. Default: root"
1919
echo " -y: (push) whether or not to use sudo remotely. Default: false"
2020
echo " -z: (push) the remote directory to copy Waffles to. Default: /etc/waffles"
21+
echo " -k: (push) the ssh key to use. Default: ~/.ssh/id_rsa"
2122
echo
2223
echo "Usage:"
2324
echo " waffles.sh -r <role>: apply a role to the local server"
@@ -41,14 +42,15 @@ function apply_role_locally {
4142

4243
# apply_role_remotely applies the role to a remote node
4344
function apply_role_remotely {
45+
4446
stdlib.include $role_script
4547

4648
local _include
4749
for i in "${!stdlib_remote_copy[@]}"; do
4850
if [[ $i =~ sh$ ]]; then
49-
_include="$_include --include=site/$i"
51+
_include="$_include --include=$i"
5052
else
51-
_include="$_include --include=site/$i/**"
53+
_include="$_include --include=$i/**"
5254
fi
5355
done
5456

@@ -85,8 +87,13 @@ function apply_role_remotely {
8587
_remote_ssh_command="bash waffles.sh"
8688
fi
8789

88-
rsync -azv --rsync-path="$_remote_rsync_path" --include='**/' --include='waffles.sh' --include='waffles.conf' --include='lib/**' $_include --include="site/roles/${role}.sh" --exclude='*' --prune-empty-dirs $WAFFLES_DIR/ "$_rsync_server:$WAFFLES_REMOTE_DIR"
89-
ssh $_ssh_server "cd $WAFFLES_REMOTE_DIR && $_remote_ssh_command $_args -r $role"
90+
stdlib.debug "Copying Waffles to remote server $_rsync_server"
91+
rsync -azv -e "ssh -i $WAFFLES_REMOTE_SSH_KEY" --rsync-path="$_remote_rsync_path" --include='**/' --include='waffles.sh' --include='waffles.conf' --include='lib/**' --include="$WAFFLES_SITE_DIR/roles/${role}.sh" --exclude='*' --prune-empty-dirs $WAFFLES_DIR/ "$_rsync_server:$WAFFLES_REMOTE_DIR"
92+
93+
stdlib.debug "Copying site to remote server $_rsync_server"
94+
rsync -azv -e "ssh -i $WAFFLES_REMOTE_SSH_KEY" --rsync-path="$_remote_rsync_path" --include="**/" $_include --include="roles/${role}.sh" --exclude='*' --prune-empty-dirs $WAFFLES_SITE_DIR/ "$_rsync_server:$WAFFLES_REMOTE_DIR/site/"
95+
96+
ssh -i $WAFFLES_REMOTE_SSH_KEY $_ssh_server "cd $WAFFLES_REMOTE_DIR && $_remote_ssh_command $_args -r $role"
9097
}
9198

9299
# Main Script
@@ -119,7 +126,7 @@ fi
119126
source "$WAFFLES_DIR/lib/init.sh"
120127

121128
# Parse options
122-
while getopts :dhnr:s:tu:z:y opt; do
129+
while getopts :dhnr:s:tu:z:yk: opt; do
123130
case $opt in
124131
d)
125132
WAFFLES_DEBUG=1
@@ -150,6 +157,9 @@ while getopts :dhnr:s:tu:z:y opt; do
150157
y)
151158
WAFFLES_REMOTE_SUDO="true"
152159
;;
160+
k)
161+
WAFFLES_REMOTE_SSH_KEY="$OPTARG"
162+
;;
153163
:)
154164
echo "Option -$OPTARG requires an argument." >&2
155165
help

0 commit comments

Comments
 (0)