#NEWLINE# @ task #NEWLINE# def accept_minions( ) : #NEWLINE# #INDENT# "\n    Accept salt-key's for all minions.\n    Usage:\n        fab master configurator.accept_minions\n    " #NEWLINE# if ( env . host != env . master_server . public_ip ) : #NEWLINE# #INDENT# abort ( 'tried to accept minions on a non-master server' ) #NEWLINE# #UNINDENT# def __get_accepted_minions( ) : #NEWLINE# #INDENT# 'TODO: remove when all distros support salt 0.10.5' #NEWLINE# try : #NEWLINE# #INDENT# accepted = eval ( sudo ( 'salt-key --yes --out raw --list acc' ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# accepted = eval ( sudo ( 'salt-key --raw-out --list acc' ) ) #NEWLINE# #UNINDENT# if ( type ( accepted ) == dict ) : #NEWLINE# #INDENT# return accepted [ 'minions' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return accepted #NEWLINE# #UNINDENT# #UNINDENT# minions = __get_accepted_minions ( ) #NEWLINE# slept = 0 #NEWLINE# while ( len ( minions ) != len ( settings . SERVERS ) ) : #NEWLINE# #INDENT# unaccepted = [ s [ 'servername' ] for s in settings . SERVERS if ( s [ 'servername' ] not in minions ) ] #NEWLINE# with fabric_settings ( warn_only = True ) : #NEWLINE# #INDENT# for server in unaccepted : #NEWLINE# #INDENT# sudo ( 'salt-key --quiet --accept={0} --yes' . format ( minions ) ) #NEWLINE# #UNINDENT# #UNINDENT# minions = __get_accepted_minions ( ) #NEWLINE# if ( len ( minions ) != len ( settings . SERVERS ) ) : #NEWLINE# #INDENT# local ( 'fab master configurator.restartall' ) #NEWLINE# time . sleep ( 5 ) #NEWLINE# slept += 5 #NEWLINE# print ( yellow ( 'there are still unaccpeted keys, trying again.' ) ) #NEWLINE# #UNINDENT# if ( slept > 300 ) : #NEWLINE# #INDENT# abort ( 'After 5 minutes of attempts, there still exist unaccpeted keys.' ) #NEWLINE# #UNINDENT# #UNINDENT# print ( green ( 'all keys have been accepted.' ) )