navaz
navaz

Reputation: 124

Python fabric How to send password and yes/no for user prompt

I have created a fabfile with multiple hosts.

I am automating my experiment. When i run the command "sudo adduser --ingroup hadoop hduser" it will ask for the following.

  1. New unix password
  2. confirm Password.
  3. Full Name
  4. Room,Ph,etc
  5. is this information Correct? Y/N

I would like to pass all this information as part of script without prompting user. How can i do this ?

Thanks

Navaz

Upvotes: 1

Views: 1377

Answers (2)

Jasper van den Bosch
Jasper van den Bosch

Reputation: 3218

Another option is to use fexpect, an extension of fabric that enables you to respond to prompts:

from ilogue.fexpect import expect, expecting, run 

prompts = []
prompts += expect('What is your full name?','John Doe')
prompts += expect('is this information Correct? Y/N','Y')

with expecting(prompts):
    sudo('adduser --ingroup hadoop hduser')

Upvotes: 1

Ekin Ertaç
Ekin Ertaç

Reputation: 335

Why didn't you just use pipes?

For example, for an automated auto accept, just use yes, that just outputs a neverending stream of y.

yes | rm *.txt

in your case:

local('echo 'your_super_password\n' | sudo adduser --ingroup hadoop hduser')

Upvotes: 1

Related Questions