fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] grouping tasks


From: Jeff Forcier
Subject: Re: [Fab-user] grouping tasks
Date: Wed, 3 Feb 2010 08:03:42 -0500

Hi Jiri,

Check out the usage docs about execution, they should shed a little
light on things. The gist is that right now Fab's model is to call the
command-line-specified tasks once for each host in their host list, so
subtasks will not retain their host information. This is changing in
future releases to be more flexible.

In the meantime, you can take advantage of the actual machinery that
drives the connections, namely that run/sudo/etc simply look at
env.host_string when they execute. In addition, @hosts just sets an
attribute on the function objects it decorates. So you should be able
to pull off something like this:

    from fabric.api import *
    from fabric.network import interpret_host_string

    @hosts('1.1.1.1')
    def deploy_one():
       run('this on 1')

    @hosts('2.2.2.2')
    def deploy_two():
       run('that on 2')

    def deploy():
        for subtask in [deploy_one, deploy_two]:
            for host in subtask.hosts:
                interpret_host_string(host)
                subtask()

interpret_host_string() is in master only, but if you look at the
source on Github [1] you'll see that it just sets env.host_string (the
crucial part) and also env.host/user/port. So if you're on 0.9, as
long as you set those env vars prior to calling a subtask, it should
operate pretty close to how it would "normally."

And again, this will become more natural/less hacky in a future
release, there are a number of initiatives underway already.

Hope that helps,
Jeff

[1] http://github.com/bitprophet/fabric/blob/master/fabric/network.py#L396

On Wed, Feb 3, 2010 at 4:53 AM, Jiri Barton <address@hidden> wrote:
> I don't know if I'm doing something wrong but it would not work for me.
> Consider this fabfile.py:
>
>
> from fabric.api import *
>
> @hosts('1.1.1.1')
> def deploy_one():
>    run('this on 1')
>
> @hosts('2.2.2.2')
> def deploy_two():
>    run('that on 2')
>
> def deploy():
>    deploy_one()
>    deploy_two()
>
>
> Well, if I run ``fab deploy`` it will complain about missing host
> definition for the task ``deploy``:
>
> $ fab deploy
> No hosts found. Please specify (single) host string for connection:
>
>
> I have looked all over the web only to find everyone would be running
> ``fab deploy_one deploy_two``. Which is not what I want.
>
> How can I make the script work?
> Thanks
> Jiri


-- 
Jeff Forcier
Unix sysadmin; Python/Ruby developer
http://bitprophet.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]