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

use versioned doclink for url references #74245

Merged
merged 5 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/doclink_refs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- ansible-doc will now correcty handle relative refs to 'current' ansible version
- set_fact module, removed hardcoded url to relative reference
- user module, removed hardcoded url to relative reference
19 changes: 14 additions & 5 deletions lib/ansible/cli/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import datetime
import json
import pkgutil
import os
Expand All @@ -24,7 +23,7 @@
from ansible.collections.list import list_collection_dirs
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.common._collections_compat import Container, Sequence
from ansible.module_utils.common._collections_compat import Sequence
from ansible.module_utils.common.json import AnsibleJSONEncoder
from ansible.module_utils.compat import importlib
from ansible.module_utils.six import iteritems, string_types
Expand All @@ -37,7 +36,6 @@
from ansible.utils.display import Display
from ansible.utils.plugin_docs import (
REJECTLIST,
remove_current_collection_from_versions_and_dates,
get_docstring,
get_versioned_doclink,
)
Expand Down Expand Up @@ -284,6 +282,13 @@ def _create_role_doc(self, role_names, roles_path, entry_point=None):
return result


def _doclink(url):
# assume that if it is relative, it is for docsite, ignore rest
if not url.startswith(("http", "..")):
url = get_versioned_doclink(url)
return url


class DocCLI(CLI, RoleMixin):
''' displays information on modules installed in Ansible libraries.
It displays a terse listing of plugins and their short descriptions,
Expand Down Expand Up @@ -321,8 +326,6 @@ def tty_ify(cls, text):
t = cls._ITALIC.sub(r"`\1'", text) # I(word) => `word'
t = cls._BOLD.sub(r"*\1*", t) # B(word) => *word*
t = cls._MODULE.sub("[" + r"\1" + "]", t) # M(word) => [word]
t = cls._URL.sub(r"\1", t) # U(word) => word
t = cls._LINK.sub(r"\1 <\2>", t) # L(word, url) => word <url>
t = cls._REF.sub(r"\1", t) # R(word, sphinx-ref) => word
t = cls._CONST.sub("`" + r"\1" + "'", t) # C(word) => `word'
t = cls._RULER.sub("\n{0}\n".format("-" * 13), t) # HORIZONTALLINE => -------
Expand All @@ -332,6 +335,12 @@ def tty_ify(cls, text):
t = cls._NOTES.sub(r" Note:", t) # nicer note
t = cls._SEEALSO.sub(r"", t) # remove seealso

# handle docsite refs
# U(word) => word
t = re.sub(cls._URL, lambda m: r"%s" % _doclink(m.group(1)), t)
# L(word, url) => word <url>
t = re.sub(cls._LINK, lambda m: r"%s <%s>" % (m.group(1), _doclink(m.group(2))), t)

return t

def init_parser(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/set_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- This boolean converts the variable into an actual 'fact' which will also be added to the fact cache, if fact caching is enabled.
- Normally this module creates 'host level variables' and has much higher precedence, this option changes the nature and precedence
(by 7 steps) of the variable created.
U(https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)
U(user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)
- "This actually creates 2 copies of the variable, a normal 'set_fact' host variable with high precedence and
a lower 'ansible_fact' one that is available for persistance via the facts cache plugin.
This creates a possibly confusing interaction with C(meta: clear_facts) as it will remove the 'ansible_fact' but not the host variable."
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
- On macOS systems, this value has to be cleartext. Beware of security issues.
- To create a disabled account on Linux systems, set this to C('!') or C('*').
- To create a disabled account on OpenBSD, set this to C('*************').
- See L(FAQ entry,https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module)
- See L(FAQ entry, reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module)
for details on various ways to generate these password values.
type: str
state:
Expand Down