Skip to content

Render a "Return Variables" table for roles - #492

Draft
spetrosi wants to merge 1 commit into
ansible-community:mainfrom
spetrosi:role-return-values
Draft

spetrosi wants to merge 1 commit into
ansible-community:mainfrom
spetrosi:role-return-values

Conversation

@spetrosi

Copy link
Copy Markdown

Summary

Render a Return Variables table on role documentation pages, so roles can document the variables they set the same way modules document their return values. Implements the renderer half of #491.

Roles declare an optional return: block per entry point in meta/argument_specs.yml (same structure as module RETURN). ansible-doc -t role --json already passes this key through untouched, so no ansible-core change is needed for the data to arrive — this PR makes antsibull-docs ingest and render it. Roles without a return: block are completely unaffected.

Changes

  • RoleEntrypointSchema now inherits PluginReturnSchema, so the return field is parsed for role entry points.
  • augment_docs computes full keys for role return values (so RV() references resolve).
  • The ansible-docsite and simplified-rst role templates render the section using the existing returnvalues.rst.j2 macro.
  • The section is titled "Return Variables" (rather than modules' "Return Values"), since a role sets variables rather than returning a structured result.
  • RV(fqcn#role:entrypoint:name) markup already worked (groundwork from Support semantic markup for roles #113) and now has real targets to resolve against.

Tests

  • Added a return: block to the ns2.col.foo fixture role (a bool plus a list/contains, exercising O() and RV() cross-references) and regenerated all baselines.
  • Extended the role schema snapshot fixture.
  • nox -e formatters, codeqa, typing, and test all pass.

Context / status

This is part of a cross-repo effort (companion PRs planned for ansible-lint's role-arg-spec.json schema and, optionally, ansible-core's ansible-doc text output).

As discussed in #491, whether roles should document "return values" is an ecosystem question that needs Core-team / community buy-in. There is an open discussion on the Ansible Forum: https://forum.ansible.com/t/proposal-document-role-return-variables-in-argument-specs-yml-like-module-return/46469 — this PR is offered as the working implementation to support that discussion, and should not be merged ahead of consensus there.

Part of #491.

🤖 Generated with Claude Code

@felixfontein
felixfontein marked this pull request as draft October 13, 2026 10:29
Roles can now document the variables they set via an optional `return:`
key per entry point in meta/argument_specs.yml, reusing the module return
schema. These render as a "Return Variables" table on the role page, with
RV() references resolving against them. Roles without a `return:` block are
unaffected.

- RoleEntrypointSchema inherits PluginReturnSchema so `return` is parsed
- augment_docs computes full keys for role return values (for RV())
- ansible-docsite and simplified-rst role templates render the section,
  titled "Return Variables" (vs modules' "Return Values")
- add a return: block to the ns2.col.foo test fixture and regenerate
  baselines; extend the role schema snapshot fixture

Part of ansible-community#491
Discussion: https://forum.ansible.com/t/proposal-document-role-return-variables-in-argument-specs-yml-like-module-return/46469

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
spetrosi added a commit to spetrosi/bootloader that referenced this pull request Oct 13, 2026
Add a native return: block to meta/argument_specs.yml so the variables the
role sets are documented as a typed "Return Variables" table, the same way
modules document their return values, and render it into README.md.

- meta/argument_specs.yml: add a return: block for bootloader_reboot_required
  and bootloader_facts, with contains: describing each kernel-fact field
  (args, default, id, index, initrd, kernel, root, title) sourced from
  library/bootloader_facts.py's RETURN. Remove the old notes: "Values
  returned by the role" workaround now that the table is first-class.
- .html_to_md.py: render the Return Values table as a Markdown pipe table
  (Key / Description). Extract the shared name-column logic (contains:
  nesting via bullet depth markers, **name** *type*) from param_label into a
  reusable nested_label helper used by both Parameters and Return Values; add
  a build_returns table-builder (the return table folds Returned:/Sample:
  into the description, unlike Parameters' Choices/Default), and dispatch to
  it on the return- anchor id.
- .build_docs.sh: build with the patched antsibull-docs that renders role
  return variables (not yet in a released antsibull-docs), installed from the
  fork branch into a dedicated venv (ANTSIBULL_RV_VENV, created once/reused).
- .ansible-lint: temporarily skip schema[role-arg-spec]; the released
  ansible-lint role-arg-spec schema rejects the return: key (schema rules
  cannot be disabled with inline noqa, only via skip_list).
- Regenerate README.md and sphinx_html/ with the Return Variables table.

The .build_docs.sh venv and the ansible-lint skip are temporary until role
return: support is released upstream; remove both then.

Refs: ansible-community/antsibull-docs#491
      ansible-community/antsibull-docs#492
      https://forum.ansible.com/t/proposal-document-role-return-variables-in-argument-specs-yml-like-module-return/46469

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant