@@ -128,6 +128,40 @@ def load_all_plugins(plugin_type, basedir, coll_filter):
128128 return result
129129
130130
131+ def load_role (role_mixin , role_name , collection_name , collection_path ):
132+ result = {
133+ 'directory' : collection_path ,
134+ 'collection_name' : collection_name ,
135+ }
136+
137+ argspec = role_mixin ._load_argspec (role_name , collection_path = collection_path )
138+ fqcn , ansible_doc = role_mixin ._build_doc (
139+ role_name , collection_path , collection_name , argspec , None )
140+
141+ try :
142+ # If this fails, the documentation cannot be serialized as JSON
143+ json .dumps (ansible_doc , cls = AnsibleJSONEncoder )
144+ # Store result. This is guaranteed to be serializable
145+ result ['ansible-doc' ] = ansible_doc
146+ except Exception as e :
147+ result ['error' ] = (
148+ 'Cannot serialize documentation as JSON: %s' % to_native (e )
149+ )
150+
151+ return result
152+
153+
154+ def load_all_roles (RoleMixin , basedir , coll_filter ):
155+ role_mixin = RoleMixin ()
156+ roles = role_mixin ._find_all_collection_roles ()
157+ result = {}
158+ for role_name , collection_name , collection_path in roles :
159+ fqcn = '{1}.{0}' .format (role_name , collection_name )
160+ if match_filter (fqcn , coll_filter ):
161+ result [fqcn ] = load_role (role_mixin , role_name , collection_name , collection_path )
162+ return result
163+
164+
131165def load_collection_meta_manifest (b_manifest_path ):
132166 with open (b_manifest_path , 'rb' ) as f :
133167 meta = json .load (f )
@@ -195,6 +229,13 @@ def main(args):
195229 for plugin_type in C .DOCUMENTABLE_PLUGINS :
196230 result ['plugins' ][plugin_type ] = load_all_plugins (plugin_type , basedir , coll_filter )
197231
232+ # Export role docs
233+ RoleMixin = getattr (doc , 'RoleMixin' , None )
234+ if RoleMixin is not None :
235+ result ['plugins' ]['role' ] = load_all_roles (RoleMixin , basedir , coll_filter )
236+ else :
237+ result ['plugins' ]['role' ] = {}
238+
198239 # Export collection data
199240 b_colldirs = list_collection_dirs (coll_filter = ansible_doc_coll_filter (coll_filter ))
200241 for b_path in b_colldirs :
0 commit comments