Discussion:
[Fab-user] Fabric question
bohdan kalytovskyy
2016-09-10 00:02:48 UTC
Permalink
Need to run python script with fabric on multiple computers with out installing fabric on all of them, how can I achieve that?

Thank you.
santosh kumar
2016-09-10 16:09:15 UTC
Permalink
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.

We don't need fabric on all nodes. Make sure ssh is enabled.

On Sep 10, 2016 15:31, "bohdan kalytovskyy" <***@gmail.com> wrote:

Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?

Thank you.
Bogdan
2016-09-10 16:53:35 UTC
Permalink
I have one python script, myscript.py i imported fabric in it and it works
on my system, once i take that file to different computer with python
installed fabric stops working because fabric modules are not installed.
Question is how can i make my script work on computers with python
installed but not fabric.

Thank you.
Post by santosh kumar
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.
We don't need fabric on all nodes. Make sure ssh is enabled.
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Carlos García
2016-09-10 16:55:56 UTC
Permalink
Hi, you can pass the contents of the script file as a parameter to this
function

def run_python(script):
return run("echo -e '{contents}' | python".format(contents=script))

Then you can call it like this:

fab run_python:'$(cat script.py)' -H hostname
Post by santosh kumar
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.
We don't need fabric on all nodes. Make sure ssh is enabled.
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Bogdan
2016-09-10 17:01:13 UTC
Permalink
where is this function located, do I need to add any additional files to my
project, my project has only 1 file in it. Im sure I need to add fabric
library to my project folder so i can run my script using fabric on
different linux boxes.

On Sat, Sep 10, 2016 at 9:55 AM, Carlos García <
Post by Carlos García
Hi, you can pass the contents of the script file as a parameter to this
function
return run("echo -e '{contents}' | python".format(contents=script))
fab run_python:'$(cat script.py)' -H hostname
Post by santosh kumar
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.
We don't need fabric on all nodes. Make sure ssh is enabled.
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Carlos García
2016-09-10 18:13:28 UTC
Permalink
Hi Bogdan

You should put the function in the fabfile.py. Anyway, if your script
imports fabric, then you need to install fabric in the target machines, or
refactor it. Take a look to virtualenv if you really need to install fabric
on remote machines.
Post by Bogdan
where is this function located, do I need to add any additional files to
my project, my project has only 1 file in it. Im sure I need to add fabric
library to my project folder so i can run my script using fabric on
different linux boxes.
Post by Bogdan
On Sat, Sep 10, 2016 at 9:55 AM, Carlos García <
Post by Carlos García
Hi, you can pass the contents of the script file as a parameter to this
function
Post by Bogdan
Post by Carlos García
return run("echo -e '{contents}' | python".format(contents=script))
fab run_python:'$(cat script.py)' -H hostname
Post by santosh kumar
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.
We don't need fabric on all nodes. Make sure ssh is enabled.
Post by bohdan kalytovskyy
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Post by Bogdan
Post by Carlos García
Post by santosh kumar
Post by bohdan kalytovskyy
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
<https://lists.nongnu.org/mailman/listinfo/fab-user>
Post by Bogdan
Post by Carlos García
Post by santosh kumar
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
<https://lists.nongnu.org/mailman/listinfo/fab-user>
Brandon Whaley
2016-09-10 18:40:33 UTC
Permalink
Hi Bogdan, you have to have fabric on the remote system to import fabric
from a python file. If you don't want to do this globally on the system,
just set up a virtualenv as your user. There are plenty of tutorials for
using virtualenv online.

On Sat, Sep 10, 2016 at 2:13 PM Carlos García <
Post by Carlos García
Hi Bogdan
You should put the function in the fabfile.py. Anyway, if your script
imports fabric, then you need to install fabric in the target machines, or
refactor it. Take a look to virtualenv if you really need to install fabric
on remote machines.
Post by Bogdan
where is this function located, do I need to add any additional files to
my project, my project has only 1 file in it. Im sure I need to add fabric
library to my project folder so i can run my script using fabric on
different linux boxes.
Post by Bogdan
On Sat, Sep 10, 2016 at 9:55 AM, Carlos García <
Post by Carlos García
Hi, you can pass the contents of the script file as a parameter to this
function
Post by Bogdan
Post by Carlos García
return run("echo -e '{contents}' | python".format(contents=script))
fab run_python:'$(cat script.py)' -H hostname
Post by santosh kumar
* U can use the put function to dump the Python file in all systems.
* Later run in using another function.
We don't need fabric on all nodes. Make sure ssh is enabled.
Post by bohdan kalytovskyy
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Post by Bogdan
Post by Carlos García
Post by santosh kumar
Post by bohdan kalytovskyy
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
<https://lists.nongnu.org/mailman/listinfo/fab-user>
Post by Bogdan
Post by Carlos García
Post by santosh kumar
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
<https://lists.nongnu.org/mailman/listinfo/fab-user>
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
R M Waters
2016-09-10 22:36:12 UTC
Permalink
Fabric is more suitable for running shell commands remotely - think about
the commands in your fabfile as abstractions on top of what a shell
offers. If you are thinking that you need to install fabric on each
machine, you should consider rethinking your approach as it might be easier
than you realize.

Your fabfile issues instructions via run/sudo/cd/et al and the 'fab'
command runs those instructions on N remote computers for you. You don't
run the fabfile on each computer - the fabfile is designed to connect, via
ssh, to the other computers and run the shell commands that are beneath the
python abstractions.

If you absolutely had to run a python script remotely, and that script was
not installed on those servers, you could use fabric to install the script
on the remote system and then execute it. This requires that your servers
have python, pip/setuptools, and any system-level dependencies that are
needed. Those servers do not need fabric to be installed.

Method 1: Store the python package in a central location (github or
something) and, in your fabfile, issue commands to download and install
that package and it's dependencies, and then execute the script.
'run("wget something"); run("pip install -e ./something")'.

Method 2: Use fabric to copy the python package to the remote servers, and
do the same as above

Method 3: Store a pre-'compiled' virtualenv with your script, and use the
copy command to push the whole thing to the servers. This will require
your virtualenv be built for the target architecture of the remote
servers. I mention but don't recommend it, unless your whole fleet is
identical.
Post by bohdan kalytovskyy
Need to run python script with fabric on multiple computers with out
installing fabric on all of them, how can I achieve that?
Thank you.
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...