1

I have two usernames and corresponding passwords that I use to admin my servers, is there a way to have my fab scripts/modules, use one and then the second if the first one failed, with out having to maintain a full list of credentials for each host or even group of them.

I see no way in the docs to doa try/except around run() or similar...

lrhazi
  • 53
  • 1
  • 8

1 Answers1

1

run and other commands raise SystemExit

from fabric.api import run,cd,put,sudo,settings

def do_stuff():
    run('ls derp')

try:
    with(settings(host_string='%s@localhost' % first_user,password = first_password)):
        do_stuff()
except SystemExit:
    with(settings(host_string='%s@localhost' % second_user,password = second_password)):
        do_stuff()
robert
  • 5,093
  • 2
  • 20
  • 21
  • Thanks, this is helpful. To do this though, I'd have to wrap every call in a `try/except` block. Is there any way in the Fabric settings to do this or somewhere top-level, similar to how you can set `env.warn_only`? – jdotjdot Jun 02 '14 at 00:51
  • jdotjdot, you should only have to wrap every call in a try/except, if every call needs to try two passwords, right? – robert Jun 24 '14 at 17:14
  • This actually wasn't my SO question; I had something similar but not quite this use case. – jdotjdot Jun 24 '14 at 18:13