I`m trying to use fabric to install and deploy a web project during which I need to create a postgresql database and configure a RabbitMQ server. Both these operations are interactive and requires input from the user for creating a database, adding a user, setting password etc ( at least to my knowledge ).
Can I use a fabric script to do interative shell operations like these?
run (fabric.operations.run) Fabric’s run procedure is used for executing a shell command on one or more remote hosts. The output results of run can be captured using a variable. If command succeeded or failed can be checked using.failed and.succeeded.
Along with run, the most widely used Fabric command is probably sudo. It allows the execution of a given set of commands and arguments with sudo (i.e. superuser) privileges on the remote host.
As long as the very basic requirements are met, you can take advantage of this excellent library. Fabric scripts are basic Python files. They are run using the fab tool that is shipped with with Fabric. All this does is include (i.e. import ..) your script (i.e. instructions to perform) and execute the provided procedure.
You basically write rules that do something and then you (can) specify on which servers the rules will run on. Fabric then logs into one or more servers in turn and executes the shell commands defined in "fabfile.py".
This is in Fabric 1.0. I've tried it and it works for me.
Older versions of Fabric (and similar high level SSH libraries) run remote programs in limbo, unable to be touched from the local end. This is problematic when you have a serious need to enter passwords or otherwise interact with the remote program.
Fabric 1.0 and later breaks down this wall and ensures you can always talk to the other side.
Source
Edit: As payne notes below, Fabric 1.0 was released. I edited the answer to indicate this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With