def to_safe(word):
 return re.sub('[^A-Za-z0-9\\-]', '_', word)

def to_safe ( word ) : return re . sub ( '[^A-Za-z0-9\\-]' , '_' , word )
converts bad characters in a string to underscores so they can be used as ansible groups .