1

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")
binithb
  • 1,910
  • 4
  • 23
  • 44
  • 2
    This should answer your question http://stackoverflow.com/questions/2339735/fabric-password – Viren Rajput Jun 04 '13 at 15:11
  • you could try `@with_settings(password=host_password)` – jfs Jun 04 '13 at 19:13
  • No luck with @with_settings(password=host_password) I go the error- Task testhosts.tasks.my_celery_task[65a6af85-9d41-45c0-add1-740f42962234] raised exception: NameError("global name 'with_settings' is not defined",) – binithb Jun 05 '13 at 08:47
  • Your link helped @VirendraRajput , I have updated the question with working code now. However the question remains - Is this the correct way ? Is there no decorator using which I can pass password as well? – binithb Jun 05 '13 at 08:53

1 Answers1

2

Skip worrying about the password and just do ssh keygens. Share the keys between the hosts you will be connecting to and you can do passwordless ssh operations on the remote hosts.

kmarks2
  • 4,755
  • 10
  • 48
  • 77
  • In my scenario I need to connect to server x and y dynamically , since my user interface is a web application. So I guess it wont be easy for me to setup ssh keygens. – binithb Jun 05 '13 at 08:34
  • Do you control servers X and Y? – kmarks2 Jun 05 '13 at 15:38
  • I will get ssh username and password of servers X and Y, these info the user will be entering in the web application.After the web application has accepted the username and password, it should go ahead and install some software in the servers X and Y- This is the scenario. – binithb Jun 06 '13 at 12:12