fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] fabric to retrieve information from systems


From: Jeff Forcier
Subject: Re: [Fab-user] fabric to retrieve information from systems
Date: Tue, 13 Dec 2011 16:08:47 -0800

On Tue, Dec 13, 2011 at 2:58 PM, Geoff Crompton
<address@hidden> wrote:

> How do I make fabric run some python code at the end of it's execution to do
> json.dump(unames)?

Right now there are no "hooks" to run after everything completes
(module-level code serves as a de facto "before" hook, though) so
you'd need to do one of two things:

A) Write a 2nd, 'local only' task decorated with @runs_once that does
the Python work needed, e.g. persisting your dict to disk:

    def get_uname():
        # update unames

    @runs_once
    def persist():
        with open('myfile.txt', 'w') as fd:
            fd.write(str(unames))

and run as:

    $ fab -H my,host,list get_uname persist

'persist' will run once only, at the end.

B) Use execute() with a specific host list argument, instead of using
global host lists set as env.hosts or via -H, from a 'wrapper' task:

    myhosts = ['my', 'host', 'list']

    def _get_uname():
        # update unames

    def get_uname():
        execute(_get_uname, hosts=myhosts)
        # persist to disk here

Invoke as:

    $ fab get_uname


These are the current methods for splitting execution between a "runs
many times" per-host subroutine, and a "runs once" local-work
subroutine. Hope it helps.

-Jeff

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



reply via email to

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