Discussion:
[Fab-user] Consolidating tasks that target both local and remote environments
Paul Walsh
2013-11-10 15:16:16 UTC
Permalink
Hi all,

I've been using Fabric for some time, and just learning what I need to know as I need to know it.

However, in the last months, I've started packaging up my commonly used tasks so I can just include the package in my various projects, and not copy/paste my fabfiles.

In packaging my code, I looked for ways to make things more generic, and the one thing I find annoying in this endeavour is the distinction between `local` on one hand, and `run` & `sudo` on the other. I have quite a bit of code that I end up writing twice - one task to wrap calls in local, and another one exactly the same, but using run and/or sudo.

I am wondering if there are any best practices for dealing with this.

A simple example:

#fabfile/local.py
@task
def db_drop():
local('code to drop the db')

#fabfile/remote.py
@task
db_drop():
run('code to drop the db')
Jens Rantil
2013-11-10 16:06:39 UTC
Permalink
Hi Paul,

I have a function that uses `local` for localhost, and `run` otherwise. See
https://gist.github.com/JensRantil/655b7f9ecd5af933f792 Not sure it solves
your problem, but maybe could inspire you?

Cheers,
Jens
Post by Paul Walsh
Hi all,
I've been using Fabric for some time, and just learning what I need to
know as I need to know it.
However, in the last months, I've started packaging up my commonly used
tasks so I can just include the package in my various projects, and not
copy/paste my fabfiles.
In packaging my code, I looked for ways to make things more generic, and
the one thing I find annoying in this endeavour is the distinction between
`local` on one hand, and `run` & `sudo` on the other. I have quite a bit of
code that I end up writing twice - one task to wrap calls in local, and
another one exactly the same, but using run and/or sudo.
I am wondering if there are any best practices for dealing with this.
#fabfile/local.py
@task
local('code to drop the db')
#fabfile/remote.py
@task
run('code to drop the db')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Paul Walsh
2013-11-10 16:08:45 UTC
Permalink
Hi Jens,

That is a nice solution, thanks. I'll try something in this direction.
Post by Jens Rantil
Hi Paul,
I have a function that uses `local` for localhost, and `run` otherwise. See https://gist.github.com/JensRantil/655b7f9ecd5af933f792 Not sure it solves your problem, but maybe could inspire you?
Cheers,
Jens
Hi all,
I've been using Fabric for some time, and just learning what I need to know as I need to know it.
However, in the last months, I've started packaging up my commonly used tasks so I can just include the package in my various projects, and not copy/paste my fabfiles.
In packaging my code, I looked for ways to make things more generic, and the one thing I find annoying in this endeavour is the distinction between `local` on one hand, and `run` & `sudo` on the other. I have quite a bit of code that I end up writing twice - one task to wrap calls in local, and another one exactly the same, but using run and/or sudo.
I am wondering if there are any best practices for dealing with this.
#fabfile/local.py
@task
local('code to drop the db')
#fabfile/remote.py
@task
run('code to drop the db')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Todd DeLuca
2013-11-10 16:28:12 UTC
Permalink
I've found that running sshd on localhost allows one to treat it like a
remote host when writing tasks.

Todd DeLuca
http://www.todddeluca.com
http://www.linkedin.com/in/todddeluca
Snt frm my tny kbrd
Post by Paul Walsh
Hi Jens,
That is a nice solution, thanks. I'll try something in this direction.
Hi Paul,
I have a function that uses `local` for localhost, and `run` otherwise.
See https://gist.github.com/JensRantil/655b7f9ecd5af933f792 Not sure it
solves your problem, but maybe could inspire you?
Cheers,
Jens
Post by Paul Walsh
Hi all,
I've been using Fabric for some time, and just learning what I need to
know as I need to know it.
However, in the last months, I've started packaging up my commonly used
tasks so I can just include the package in my various projects, and not
copy/paste my fabfiles.
In packaging my code, I looked for ways to make things more generic, and
the one thing I find annoying in this endeavour is the distinction between
`local` on one hand, and `run` & `sudo` on the other. I have quite a bit of
code that I end up writing twice - one task to wrap calls in local, and
another one exactly the same, but using run and/or sudo.
I am wondering if there are any best practices for dealing with this.
#fabfile/local.py
@task
local('code to drop the db')
#fabfile/remote.py
@task
run('code to drop the db')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Paul Walsh
2013-11-10 17:09:03 UTC
Permalink
That is a good idea that would lead to very clean code. So, "127.0.0.1" is just another "remote host".

I'll give it a try, thanks.
I've found that running sshd on localhost allows one to treat it like a remote host when writing tasks.
Todd DeLuca
http://www.todddeluca.com
http://www.linkedin.com/in/todddeluca
Snt frm my tny kbrd
Hi Jens,
That is a nice solution, thanks. I'll try something in this direction.
Post by Jens Rantil
Hi Paul,
I have a function that uses `local` for localhost, and `run` otherwise. See https://gist.github.com/JensRantil/655b7f9ecd5af933f792 Not sure it solves your problem, but maybe could inspire you?
Cheers,
Jens
Hi all,
I've been using Fabric for some time, and just learning what I need to know as I need to know it.
However, in the last months, I've started packaging up my commonly used tasks so I can just include the package in my various projects, and not copy/paste my fabfiles.
In packaging my code, I looked for ways to make things more generic, and the one thing I find annoying in this endeavour is the distinction between `local` on one hand, and `run` & `sudo` on the other. I have quite a bit of code that I end up writing twice - one task to wrap calls in local, and another one exactly the same, but using run and/or sudo.
I am wondering if there are any best practices for dealing with this.
#fabfile/local.py
@task
local('code to drop the db')
#fabfile/remote.py
@task
run('code to drop the db')
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...