How do you specify a different target to run a command on other than the one that's currently set for the running Fabric command?
I have a command download_backup() that downloads a database backup file to the localhost from a remote host. Since it has to run locally, the host_string is localhost. However, I need to run a command on the remote host to find what the most recent backup is. When I try to do:
def download_backup():
env.host_string = 'remotehost'
env.user = 'remoteuser'
backup_fn = run('ls -t /usr/local/lib/backups | head -1')
it still attempts to run the ls
command on localhost. I do I change this to run on remotehost?
you could use the settings context manager to change the host that a specific command runs on, independent of the host setting for the enclosing task.
from fabric.context_managers import settings
with settings(host_string='remote_server'):
run('ls -lart')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With