[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?
From: |
Brandon Whaley |
Subject: |
Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2? |
Date: |
Mon, 1 Apr 2019 11:36:59 -0400 |
Hi Mich,
The connection object (you're using ctx in your examples) has a .local
method that is just a pass-through to invoke.run. It's documented on
the connection object's page:
http://docs.fabfile.org/en/2.4/api/connection.html?highlight=local#fabric.connection.Connection.local
On Mon, Apr 1, 2019 at 5:55 AM Michel Albert <address@hidden> wrote:
>
> Hi,
>
>
> Consider the following fabric-1 task. For illustration I kept it really short:
>
> @fab.task
> def sample():
> version = fab.local('python setup.py --version')
> fab.run('mkdir -p /snapshots/%s' % version.strip())
>
> This task needs to run a local and remote command. I am now trying to port
> this to fabric-2, and I can't figure out how I can implement this. If I
> define the "hosts" variable in the task, then the first line will be executed
> on the remote host as well, which I don't want. A naive aproach which won't
> work:
>
> @task(hosts=PROD)
> def sample(ctx):
> version = ctx.run('python setup.py --version').strip() # <- this won't
> work
> ctx.run('mkdir -p /snapshots/%s' % version)
>
> At first I thought I would split the task into two, one for just local
> commands and one for remote tasks, but then I am forced to pass in the
> context, which will in turn cause it again to be run remotely:
>
> @task
> def get_version(ctx):
> version = ctx.run('python setup.py --version').strip()
> return version
>
> @task(hosts=PROD)
> def sample(ctx):
> version = get_version(ctx) # <- this won't work
> ctx.run('mkdir -p /snapshots/%s' % version)
>
> How can I accomplish something like this? And where is it noted in the docs?
> In the current example on the "Upgrading from 1.x" page does not have a
> single task mixing local with remote commands in any way.
>
>
> Regards,
>
>
> Mich
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
- [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Michel Albert, 2019/04/01
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?,
Brandon Whaley <=
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Michel Albert, 2019/04/01
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Brandon Whaley, 2019/04/01
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Michel Albert, 2019/04/02
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Brandon Whaley, 2019/04/02
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Michel Albert, 2019/04/02
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Brandon Whaley, 2019/04/02
- Re: [Fab-user] How do I combine "local" with "remote" tasks in fabric 2?, Michel Albert, 2019/04/02