diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-10-05 12:08:00 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-10-05 12:08:00 -0300 |
commit | 73b8f423dbc3c1827eec968c326748c218a6d5b1 (patch) | |
tree | b15c643c724fd28ce17e994f5844e5d7b99ccd45 | |
parent | e55f839397fc348ac20228ebe166382171f9ac8b (diff) | |
download | hydra-73b8f423dbc3c1827eec968c326748c218a6d5b1.tar.gz hydra-73b8f423dbc3c1827eec968c326748c218a6d5b1.tar.bz2 |
Mass: check if current host is localhost
-rw-r--r-- | doc/todo.rst | 1 | ||||
-rwxr-xr-x | share/hydra/mass | 30 |
2 files changed, 26 insertions, 5 deletions
diff --git a/doc/todo.rst b/doc/todo.rst index e064e46..28fed93 100644 --- a/doc/todo.rst +++ b/doc/todo.rst @@ -1,7 +1,6 @@ TODO ==== -- mass: check if current host is localhost. - mount-media: lvm support. - import-certs: - concat.pem. diff --git a/share/hydra/mass b/share/hydra/mass index ba5bddd..871468c 100755 --- a/share/hydra/mass +++ b/share/hydra/mass @@ -43,11 +43,23 @@ function mass_mussh { } # Set nodes -function set_nodes { +function mass_set_nodes { hydra_set_tmpfile nodes hydra $HYDRA nodes $1 > $TMPWORK } +# Execute command on localhost +function mass_exec_localhost { + if grep -q -e "^$LOCAL$" $TMPWORK; then + # Remove localhost from node list + grep -v -e "^$LOCAL$" $TMPWORK > $TMPWORK.tmp + mv $TMPWORK.tmp $TMPWORK + + echo "Issuing command on localhost..." + $SUDO $COMMAND + fi +} + # Load source $APP_BASE/lib/hydra/functions || exit 1 hydra_config_load @@ -58,16 +70,26 @@ COMMAND="$*" # Initial node list BASEDIR="/tmp" -set_nodes +LOCAL="`facter fqdn`" +mass_set_nodes + +# Set sudo config +if [ "$WHOAMI" != 'root' ]; then + sudo="sudo" +else + echo "Sorry, cannot run as root" + exit 1 +fi # Validation if [ "$BASENAME" == "mass-upgrade" ]; then COMMAND="DEBIAN_FRONTEND=noninteractive hydractl upgrade clean" elif [ "$BASENAME" == "mass-web" ]; then - set_nodes web + mass_set_nodes web fi # Execute commands in hosts echo "Issuing $COMMAND on multiple nodes..." -mass_pssh $COMMAND +mass_exec_localhost +mass_pssh hydra_unset_tmpfile $TMPWORK |