Discussion:
[Fab-user] Purely local tasks
Jon Dufresne
2013-09-24 01:00:59 UTC
Permalink
Hi,

Does Fabric have a concept of purely local tasks?

Part of my fabfile loads an external JSON file to build fabric's env hosts
and other variables. I have created a task to dump this information back to
stdout (for testing and debugging). This task never interacts with a host.
In my mind, it is a purely local task. When using puts() with
show_prefix=True, Fabric shows that this task is running with the first
host. Curious if there is a better way to do this.

Thanks,
Jon
Jorge Vargas
2013-09-24 01:13:27 UTC
Permalink
Sadly no, if you search the archives they are many attempts to do this and
in the end the best option is to just use local() all over the place, which
removes some of the advanced functions of fabric like the puts() you
mention.

Or configure your machine/environment in a way that fabric can ssh to the
same machine you are runnings things from foolling it into thinking it's a
remote machine.
Post by Jon Dufresne
Hi,
Does Fabric have a concept of purely local tasks?
Part of my fabfile loads an external JSON file to build fabric's env hosts
and other variables. I have created a task to dump this information back to
stdout (for testing and debugging). This task never interacts with a host.
In my mind, it is a purely local task. When using puts() with
show_prefix=True, Fabric shows that this task is running with the first
host. Curious if there is a better way to do this.
Thanks,
Jon
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Jon Dufresne
2013-09-24 03:00:10 UTC
Permalink
Post by Jorge Vargas
Sadly no, if you search the archives they are many attempts to do this and
in the end the best option is to just use local() all over the place, which
removes some of the advanced functions of fabric like the puts() you
mention.
As in local('echo ...'), or should I simply use Python's print at this
point?
Post by Jorge Vargas
Or configure your machine/environment in a way that fabric can ssh to the
same machine you are runnings things from foolling it into thinking it's a
remote machine.
Something like this?

def local_task(f):
user = getpass.getuser()
wrapper = hosts('%***@localhost' % user)
return wrapper(task(f))

@local_task
def my_task():
...

Is this reliable across multiple environments? Will this require the
running machine to also be running an SSH server?

Which of these to solutions is better in the end?

Thanks,
Jon
Jorge Vargas
2013-09-26 05:39:36 UTC
Permalink
Post by Jon Dufresne
Post by Jorge Vargas
Sadly no, if you search the archives they are many attempts to do this
and in the end the best option is to just use local() all over the place,
which removes some of the advanced functions of fabric like the puts() you
mention.
As in local('echo ...'), or should I simply use Python's print at this
point?
print is what I do.
Post by Jon Dufresne
Post by Jorge Vargas
Or configure your machine/environment in a way that fabric can ssh to the
same machine you are runnings things from foolling it into thinking it's a
remote machine.
Something like this?
user = getpass.getuser()
return wrapper(task(f))
@local_task
...
Is this reliable across multiple environments? Will this require the
running machine to also be running an SSH server?
yes and yes.
Post by Jon Dufresne
Which of these to solutions is better in the end?
Again it depends on how much of fabric you use. if your task uses anything
other than local() you are probably best using the SSH into your own
machine.
Post by Jon Dufresne
Thanks,
Jon
Loading...