Is there a way to make Fabric summarize results across multiple hosts?

When I administer dozens of servers using Fabric, I often do not need the features of the commands running on each server, instead I want to map small bits of information from each host and present it in the summary at the end.

Does Fabric support this functionality? (I searched the documentation to no avail, but maybe I missed something).

Otherwise, I suppose, it would be possible to aggregate this information manually and then add an exit handler, but this seems like a normal use case.

As an example, I have several scripts that perform some basic security checks on multiple servers, and I would like to create a report at the end instead of scrolling through the output for each server. I do not want to limit the output of Fabric, because if there is a problem, I want to scroll back to pinpoint it.

+5
source share
2 answers

Most likely this is a bit dated, and Fabric has certainly changed a lot since you asked this question ... although, as Morgan said, you just need a shell script to contain the workhorse, and then it is "just Python" from there. This is briefly described in the documentation.

, , , - "uptime" (, , ):

@parallel
def _get_uptime():
  '''Retrieve and return uptime for each host'''
  with hide('stdout'):
    up = run( 'uptime' )
  return( up.rstrip() )

@runs_once
def uptime_sorted():
  '''System: System uptime (sorted) - Use parallel for best effect'''
  print( cyan( "[%(host)s] Executing on %(host)s as %(user)s" % env ) )
  system_uptimes = execute( _get_uptime )
  for sys,up in sorted( system_uptimes.iteritems() ):
    print "%s: %s" % ( sys, up )

uptime_sorted . _get_uptime .

+2

python, , , , . , , .

+1

All Articles