ansible-doc fix YAML examples rendering#84467
Conversation
|
In case you want to look at this one too, and only applies to modules: That always assumes that |
|
@sivel, looking at that, it ONLY checks modules, it should really check most plugins ... might need it's own PR |
ae27fe0 to
70ca0a3
Compare
069c8c2 to
63603de
Compare
63603de to
6174c23
Compare
| else: | ||
| try: | ||
| text.append(yaml_dump(doc.pop('examples'), indent=2, default_flow_style=False)) | ||
| text.append(DocCLI._dump_yaml(doc.pop('examples'))) |
There was a problem hiding this comment.
Is there a reason we're using the AnsibleLoader and AnsibleDumper instead of the normal loader and dumper?
There was a problem hiding this comment.
!vault and !unsafe in examples break otherwise
There was a problem hiding this comment.
Examples should only be accepted as text, not structured data. Attempting to load them as anything other than text loses comments, formatting and !unsafe, as well as complicates the loading and dumping. Using the normal YAML loader and dumper will allow non-text examples to pass through as long as they don't use ansible specific tags. The validate-modules sanity test should be updated to report an error (if it doesn't already) when the examples are not text, so that developers know to correct their examples.
In the future we could implement a feature to allow validating the text examples in whatever format(s) we'd like to support, such as YAML, but that's not something we should try to design now.
There was a problem hiding this comment.
There doesn't appear to be a good reason to add support to ansible-doc for dumping Ansible-specific types. Switching to the standard YAML loader for sidecar will avoid the need for that.
Looking at collections on Galaxy, there's no usage of Ansible YAML tags in sidecar docs. Even if someone was using them, the docs are already broken -- either generating tracebacks or rendering incorrectly. So we shouldn't need to worry about introducing new issues by changing the loader.
There was a problem hiding this comment.
This is not a new feature but fixing the exiting feature to align with what would be the logical expectation, that ansible documentation can handle ansible specific yaml.
Also, I'm sure no one is using a feature that would currently break their docs, that does not mean they have not tried nor want to.
| else: | ||
| try: | ||
| text.append(yaml_dump(doc.pop('examples'), indent=2, default_flow_style=False)) | ||
| text.append(DocCLI._dump_yaml(doc.pop('examples'))) |
There was a problem hiding this comment.
Examples should only be accepted as text, not structured data. Attempting to load them as anything other than text loses comments, formatting and !unsafe, as well as complicates the loading and dumping. Using the normal YAML loader and dumper will allow non-text examples to pass through as long as they don't use ansible specific tags. The validate-modules sanity test should be updated to report an error (if it doesn't already) when the examples are not text, so that developers know to correct their examples.
In the future we could implement a feature to allow validating the text examples in whatever format(s) we'd like to support, such as YAML, but that's not something we should try to design now.
475b383 to
ca98ae9
Compare
test sidecar inventory plugin with yaml examples added now required examples to test plugins fix test to get array length dynamically
this seems legacy copy/paste and not intended for use with role specs
Co-authored-by: Matt Clay <matt@mystile.com>
This reverts commit 6174c23.
Co-authored-by: Matt Clay <matt@mystile.com>
ca98ae9 to
c5d949e
Compare
Also fixing ansible-test
ISSUE TYPE
ADDITIONAL INFORMATION
https://forum.ansible.com/t/add-documentation-for-examples-in-the-adjacent-documentation/39048
https://github.com/scaleway/ansible/blob/ruff_check/plugins/inventory/scaleway.yml