Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure ansible-docs display boolean values using true/false #78557

Closed
wants to merge 1 commit into from

Conversation

ssbarnea
Copy link
Member

Adopts JSON/YAML 1.2 standard booleans names.

Related: ansible-community/community-topics#116

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
  • Test Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION

@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. affects_2.14 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Aug 16, 2022
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Aug 16, 2022
if isinstance(obj, bool):
# Return JSON/YAML 1.2 standardized true/false values
return "true" if obj else "false"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely the wrong place for this to happen. This function should not concern itself with YAML serialization. This is basically just Python conversion to text type, not special case modifications to non python types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivel given your deep knowledge and experience with ansible, could you take a few minutes to get me headed in the right direction? A couple pointers into the code would be great. I really want to get this right.

As part of mentioned change, we want to ensure that we only display booleans as true, false to the user, including output of ansible-doc <module>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should already be the case except where 'python stringification' takes place, ... which affects fields like Default but not most others. Removing the python stringification would make it match.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will likely have to make modifications in every location that outputs the value.

In the case of ansible-doc, the change would be required in lib/ansible/cli/doc.py::DocCLI.add_fields. A new helper function might be required to avoid duplication. The change likely needs to happen for the default value, as well as choices.

Something like:

default = "[Default: %s" % to_text(_coerce_bool_to_yaml(opt.pop('default', '(null)'))) + "]"

@ansibot
Copy link
Contributor

ansibot commented Aug 16, 2022

The test ansible-test sanity --test ansible-doc [explain] failed with the error:

Output on stderr from ansible-doc is considered an error.

Command "ansible-doc -t become runas su sudo" returned exit status 0.
>>> Standard Error
�[1;35m[WARNING]: You are running the development version of Ansible. You should only
�[1;35mrun Ansible from "devel" if you are modifying the Ansible engine, or trying out
�[1;35mfeatures under development. This is a rapidly changing source of code and can
�[1;35mbecome unstable at any point.

The test ansible-test sanity --test import --python 3.9 [explain] failed with 10 errors:

lib/ansible/plugins/inventory/__init__.py:0:0: stdout: �[1;30m   244 1660662676.25904: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/advanced_host_list.py:0:0: stdout: �[1;30m   244 1660662676.46643: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/auto.py:0:0: stdout: �[1;30m   244 1660662676.66129: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/constructed.py:0:0: stdout: �[1;30m   244 1660662676.89622: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/generator.py:0:0: stdout: �[1;30m   244 1660662677.09583: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/host_list.py:0:0: stdout: �[1;30m   244 1660662677.33248: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/ini.py:0:0: stdout: �[1;30m   244 1660662677.53513: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/script.py:0:0: stdout: �[1;30m   244 1660662677.77478: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/toml.py:0:0: stdout: �[1;30m   244 1660662677.98461: trying /root/ansible/lib/ansible/plugins/cache
lib/ansible/plugins/inventory/yaml.py:0:0: stdout: �[1;30m   244 1660662678.17048: trying /root/ansible/lib/ansible/plugins/cache

click here for bot help

@bcoca
Copy link
Member

bcoca commented Aug 16, 2022

#78561

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 24, 2022
@mkrizek
Copy link
Contributor

mkrizek commented Sep 6, 2022

Closing in favor of #78668

@mkrizek mkrizek closed this Sep 6, 2022
@ansible ansible locked and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.14 bug This issue/PR relates to a bug. has_issue small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team. WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants