0

I have two problems I am trying to solve with fabric for python.

  1. I'd like to auto-enter the password at the prompt:
  2. I'd like to auto-respond to prompts based on the output of a session:

Both of these should be possible as the above links show, but I can't get them to work. When I run the following file via fab test

from fabric.api import run, env, settings

env.hosts = ['<user>@<host>']
env.passwords = {'<user>@<host>': '<password>'}

def test():
    with settings(prompts={"Please select a menu item: ": "1",}):
        return
    run("ls")

My output is:

[<user>@<host>] Login password for '<user>':

At which point I have to type my password, instead of auto-entering. Then per the remote host I get a menu which I want to auto respond to, but my prompt's auto-complete doesn't work.

[<user>@<host>] out: <a menu>
[<user>@<host>] out: Please select a menu item: 

What do I need to do to get this to auto-enter my password and auto-answer this prompt?

Community
  • 1
  • 1
Ethan Kay
  • 657
  • 6
  • 24

1 Answers1

0

If you look at the documentation on env.passwords it says:

This dictionary is largely for internal use, and is filled automatically as a per-host-string password cache. Keys are full host strings and values are passwords (strings).

The important note is the warning following the above:

Warning

If you modify or generate this dict manually, you must use fully qualified host strings with user and port values. See the link above for details on the host string API.

Following the above warning, make sure that the hostname is FQDN and perhaps even add the port number :22 and see if it works.

As for the prompt, that should have worked as long as you ran the command inside the with block (which I can't tell from your sample code). Also check if the prompt is followed by a space, if not remove it from your prompts key.

haridsv
  • 9,065
  • 4
  • 62
  • 65