I am trying to use Fabric ,Django and Celery together to do operations on a remote host.
And in my case the remote host is going to be dynamic.
I guess the use of Django and Celery is irrelevant , the question can be narrowed down to
- how to supply SSH password dynamically while using Fabric alone.
I found this piece of code which shows how to do this with Django and Celery.
from fabric.api import hosts
from celery import task
@task()
def remote_celery_task():
username, host = get_host_details()
host_string = "%s@%s" % (username, host)
@hosts(host_string)
def fab_task():
run("ls")
execute(fab_task)
But what it doesnt tell is how to dynamically pass SSH passwords to Fabric. I understand that supplying password this way isnt good security wise, but I am willing to sacrifice security at the moment.
Update
I got it working when I changed the code to
@hosts(host_string)
def my_fab_task():
env.password = testhost.SSH_password # is this the correct way ? its working for me
run("ls")