fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] question about Fabric as a library


From: Jeff Forcier
Subject: Re: [Fab-user] question about Fabric as a library
Date: Thu, 5 Sep 2013 16:29:39 -0700

The values involved ought to be the same either way - have you verified this?

* sudo() returns an _AttributeString object which is the one you
mentioned as having useful attributes.
* execute() returns that dict mapping hostname to the return value of
the task function, for that hostname.
* Your task is returning the result of the sudo() calls, meaning they
should end up in the result of execute().

Therefore, you should be seeing e.g.:

    {'node1': <_AttributeString object from the sudo()>, 'node2':
<_AttributeString object from the sudo()>}

Where those _AttributeStrings are the same values you would see if you
ran your 2nd example snippet.

If you're seeing something different, clarification and specific
output examples would be great :)

Thanks,
Jeff

On Thu, Sep 5, 2013 at 1:45 PM, Vincent Derelle
<address@hidden> wrote:
> Hello,
>
>
>
> I’m developing an internal tool in our organisation. In a nutshell,  it’s a
> web app (using Python Django) which retrieves a set of nodes from a Chef
> server and then run commands on those selected nodes. I’m using Fabric
>
> to execute those commands remotely. The recommended way to use Fabric as a
> library in the documentation is to use the execute
> (http://docs.fabfile.org/en/1.7/api/core/tasks.html#fabric.tasks.execute)
>
> function.
>
>
>
> If I use the execute function like this:
>
> nodes = [‘nodes1’, ‘node2’]
>
>
>
> result = execute(_fabric_execute, command, hosts=nodes)
>
>
>
> @parallel
>
> def _fabric_execute(command):
>
>     result = sudo(command)
>
>     return result
>
>
>
> this will work and return to me a dictionary containing the output of those
> commands.
>
>
>
> If I do it sequentially instead like this:
>
> nodes = [‘nodes1’, ‘nodes2’]
>
>
>
> results = []
>
>
>
> for n in nodes:
>
>     env.host_string = n
>
>     result = _fabric_execute(command);
>
>     results.append(result)
>
>
>
> (in the django template iterate through the array and then display the
> different result object properties)
>
>
>
> The individual result objects returned give me much more valuable
> information such as: result.succeeded if it succeeded , result.failed if it
> failed, result.real_command for the real command executed as well as the the
> output.
>
>
>
> My question to you is, is there any way I can get that information when
> using the execute function? Because my web app allows people to execute
> commands, by default, in parallel which returns only the output but if they
> chose sequential execution but I’m able to display to them if it succeeded
> or not and the real command executed by fabric if they select sequential
> execution. Essentially I’d like to be able to display the same amount of
> information (mainly if it failed or not) in parallel execution using execute
> like sequential execution
>
>
>
> Cheers,
>
> I love fabric!
>
>
>
> Vincent
>
>
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
>



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



reply via email to

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