Package: tues
tuesRun any remote command via ssh and sudoInstallRunpip install tuesGetting StartedAs a commandline toolTues expects a command to execute, followed by the name of a hostname provider and its arguments.Runidon localhost as user root, using the IPv4/IPv6 adresses is not required, just passing localhost three times would work as well, you are only prompted for a password once and the original sudo prompt is stripped from the output.
The login user will be derived from your ssh configuration (or if you really need to, manually with the--login-user/-lswitch), while the user specified by-uis the user to run the command as on the remote host.$ tues -u root id cl localhost 127.0.0.1 [::1]
[::1/stdout]: uid=0(root) gid=0(root) groups=0(root)
[127.0.0.1/stdout]: uid=0(root) gid=0(root) groups=0(root)
[localhost/stdout]: uid=0(root) gid=0(root) groups=0(root)
$There are switches to send output to a directory, one file per host (-d <dir>), run on multiple hosts at a time-n <num>, upload files to the remote host before executing the command-f <file>and also a mechanic to treat the executed command as a local script inTUES_PATHthat needs to be uploaded to the host first.$ echo 'ls "$@"' > myls
$ chmod +x myls
$ echo foo > myfile
$ mkdir output
$ tues --path=. -d output -f myfile -s 'myls -la $TUES_FILE1' localhost 127.0.0.1
Starting localhost
Finished localhost
Starting 127.0.0.1
Finished 127.0.0.1
$ cat output/*
[127.0.0.1/stdout]: -rw-rw-r-- 1 mvb mvb 4 Jul 26 12:59 myfile
[localhost/stdout]: -rw-rw-r-- 1 mvb mvb 4 Jul 26 12:59 myfile
$Running with an output directory automatically enables verbose mode to show at least a bit of progress, while disabling prefixing because with one file per host, you probably won't need the prefix.
For this simple example, we setTUES_PATHto.on the commandline, by default, scripts should be placed in$HOME/.config/tues/scripts/.From PythonWhen running from python, tues will behave mostly the same, with slight differences where it makes sense. In Python mode, we need to explicitly request output prefixing for example:importtuestues.run(["localhost","127.0.0.1","[::1]"],"id",user="root",prefix=True,)Your remote sudo password:
[localhost/stdout]: uid=0(root) gid=0(root) groups=0(root)
[127.0.0.1/stdout]: uid=0(root) gid=0(root) groups=0(root)
[::1/stdout]: uid=0(root) gid=0(root) groups=0(root)
$Output is usually kept "clean" (except for the sudo output of course) for later processing:importsysimporttuesruns=tues.run(["localhost","127.0.0.1","[::1]"],"id",user="root",text=True,capture_output=True,)forruninruns:sys.stdout.write(run.stdout)The interface tries to mimicsubprocess.runwhere possible, the fact that it can run a command on multiple hosts will always require details to be handle diffrently though.$ python3 tues.py
Your remote sudo password:
uid=0(root) gid=0(root) groups=0(root)
uid=0(root) gid=0(root) groups=0(root)
uid=0(root) gid=0(root) groups=0(root)
$For a detailed description of therunArguments, pleasecheck out the docstringfor now, while I procastinate on creating proper docs. :-(ProvidersFileThefileprovider assumes all files passed on the commandline contain one host per line.CommandlineTheclprovider assumes all arguments passed on the commandline are hosts to connect to.ForemanExecute on all hosts matching a certain foreman expression.export FOREMAN_URL="https://user:password@foreman.domain/"
tues "ls" fm "class = my::class"Custom ProvidersNew providers may be added by putting a new executable with a name like "tues-provider-"
on your PATH. A provider is expected to return a newline seperated list of hosts.If the provider returns with an error, the output is considered to be an error message and/or
it's help output. If '--help' is passed through to the provider the output is displayed no matter
what exit code is used.