From 5e4f708241815ad4d5fa0aef0574310c5451029a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 30 Jun 2020 21:33:44 +0200 Subject: [PATCH] ansible-doc: avoid problems with YAML anchors when formatting man page (#70045) * Avoid problems with YAML anchors when formatting man page. * Add changelog. --- changelogs/fragments/70045-ansible-doc-yaml-anchors.yml | 2 ++ lib/ansible/cli/doc.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/70045-ansible-doc-yaml-anchors.yml diff --git a/changelogs/fragments/70045-ansible-doc-yaml-anchors.yml b/changelogs/fragments/70045-ansible-doc-yaml-anchors.yml new file mode 100644 index 00000000000..6bf2bb63788 --- /dev/null +++ b/changelogs/fragments/70045-ansible-doc-yaml-anchors.yml @@ -0,0 +1,2 @@ +bugfixes: +- "ansible-doc - improve man page formatting to avoid problems when YAML anchors are used (https://github.com/ansible/ansible/pull/70045)." diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py index cb06de7bdf3..0572ec9d59c 100644 --- a/lib/ansible/cli/doc.py +++ b/lib/ansible/cli/doc.py @@ -513,7 +513,8 @@ class DocCLI(CLI): def add_fields(text, fields, limit, opt_indent, return_values=False, base_indent=''): for o in sorted(fields): - opt = fields[o] + # Create a copy so we don't modify the original (in case YAML anchors have been used) + opt = dict(fields[o]) required = opt.pop('required', False) if not isinstance(required, bool): @@ -562,7 +563,8 @@ class DocCLI(CLI): conf = {} for config in ('env', 'ini', 'yaml', 'vars', 'keywords'): if config in opt and opt[config]: - conf[config] = opt.pop(config) + # Create a copy so we don't modify the original (in case YAML anchors have been used) + conf[config] = [dict(item) for item in opt.pop(config)] for ignore in DocCLI.IGNORE: for item in conf[config]: if ignore in item: @@ -593,6 +595,8 @@ class DocCLI(CLI): @staticmethod def get_man_text(doc): + # Create a copy so we don't modify the original + doc = dict(doc) DocCLI.IGNORE = DocCLI.IGNORE + (context.CLIARGS['type'],) opt_indent = " "