Merge "Add library documentation within roles"

This commit is contained in:
Zuul 2019-07-28 21:59:43 +00:00 committed by Gerrit Code Review
commit d029ba838b
1 changed files with 22 additions and 3 deletions

View File

@ -279,12 +279,31 @@ class AnsibleAutoPluginDirective(Directive):
self.run_returns.append(section)
def _run_module(self, module):
# Document any libraries nested within the role
library_path = os.path.join(role, 'library')
if os.path.exists(library_path):
self.options['documentation'] = True
self.options['examples'] = True
for lib in os.listdir(library_path):
if lib.endswith('.py'):
self._run_module(
module=self.load_module(
filename=os.path.join(
library_path,
lib
)
),
module_title='Embedded module: {}'.format(lib),
example_title='Examples for embedded module'
)
def _run_module(self, module, module_title="Module Documentation",
example_title="Example Tasks"):
if self.options.get('documentation'):
docs = self.build_documentation(module=module)
self.run_returns.append(
self.make_node(
title="Module Documentation",
title=module_title,
contents=docs
)
)
@ -293,7 +312,7 @@ class AnsibleAutoPluginDirective(Directive):
examples = self.build_examples(module=module)
self.run_returns.append(
self.make_node(
title="Example Tasks",
title=example_title,
contents=examples,
content_type='yaml'
)