Before diving into example usage, reader may find below an excerpt from the documentation and from the code, to help fix ideas.
Man page
Excerpt from sugar.1;
SUGAR(1) General Commands Manual SUGAR(1)
Name
sugar - a sweeter salt/ansible/chef
SYNOPSIS
sugar [-mspqa] [-d str] [-r user:group] [-c conf] <server> <cmd>
[args...]
sugar [-h]
sugar.mkautos <server> <raw/> <ready/>
sugar.imports <server> <raw/> <ready/>
. βwhich sugar.libβ
DESCRIPTION
sugar is a simple remote machine administration tool, based on ssh(1),
sh(1) and rsync(1). In essence, it synchronizes server-specific local
repositories to remote locations, and allows to run commands on said
servers, eventually wrapped between locally executed hooks.
The code is small and simple, and is likely a more precise documentation
than this man page.
OPTIONS
-m Interpret server as an awk(1) pattern instead of as a server
alias. Perform command on all servers matching the pattern.
-s Automatically synchronize servers' directories before running
cmd.
-p Only run pre-hooks, including the main pre-hook. Note that -s is
ignored if -p is specified.
-q Only run post-hooks, including the main post-hook. Note that -s
is ignored if -q is specified.
If both -p and -q are specified, then pre-hooks are always exeβ
cuted before post-hooks.
This is because pre-hooks may setup things that will be removed
by post-hooks.
See also -a below.
-a Will run the main pre-hook if -q has been specified, as it would
otherwise not be run, which can be troublesome for imported (
sugar.imports) post-hooks, which would then not be run, because
absent.
-d str Defines, forward (to hooks and remotely executed scripts), and
set to str a $DEBUG variable. Note that sugar.lib and
sugar.mkautos interpret str as a list of one-character flags: x
triggers a set -x; d enables files dumping to stderr in the temβ
plate system.
-r user:group
Owner and group for remote $SUGARD, default to root:wheel. Can be
overridden by setting $ROOT before starting sugar(1).
-c conf
Source conf if present, so that we can override e.g. $PATH,
$SUGARF, $SUGARD, $LSUGARD, $ROOT.
-h Display help message
server Describes the server, or the potential servers if -m has been
specified, on which to run cmd.
cmd Is the name of the executable we want to run.
args...
Are cmd's arguments.
...
Main loop
Excerpt from sugar:
...
lsmatches "$p" | while read s; do
ready=$LSUGARD/ready/$s
raw=$LSUGARD/raw/$s
# Ensure there's a raw/ directory configured, fail
# otherwise (common case is a symbolic link to a
# versioned directory).
if [ ! -d $raw ]; then
fail "no raw directory for $s ($raw)"
fi
# Create/update ready directory from raw directory
mkready $raw $ready
# Only execute pre/post hooks
if [ -n "$prehook" ] && [ -n "$posthook" ]; then
prehooks $1 $s $raw $ready
posthooks $1 $s $raw $ready
continue
fi
# Only execute post-hooks, eventually after the
# main pre-hook if specified
if [ -n "$posthook" ]; then
if [ -n "$mprehook" ]; then
mainhook pre $s $raw $ready
fi
posthooks $1 $s $raw $ready
continue
fi
# Run pre-hooks
prehooks $1 $s $raw $ready
# Only execute pre-hooks.
if [ -n "$prehook" ]; then
continue
fi
# Perform synchronisation if specified
if [ -n "$sync" ]; then
sync1 $s $raw $ready
fi
# Run the command on the given server
run $s $@
# Run post-hooks
posthooks $1 $s $raw $ready
done
# Make it visually clear that everything went fine.
echo OK
Comments
By email, at mathieu.bivert chez: