On Tue, Dec 13, 2011 at 2:58 PM, Geoff Crompton
<[email protected]> 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

_______________________________________________
Fab-user mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/fab-user

Reply via email to