Repository: ansible/ansible

Issue:
ansible-doc does not extend doc fragments
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
<!---
Name of the module/plugin/task/feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
ansible-doc

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
2.4.2 
devel
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
NA

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
NA

##### SUMMARY
ansible-doc does not show docs of doc fragments but shows e.g. for cs_vpc

~~~
AUTHOR: René Moser (@resmo)
EXTENDS_DOCUMENTATION_FRAGMENT: cloudstack
        METADATA:
          status:
          - stableinterface
~~~
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ansible-doc cs_vpc
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
full docs including docs in doc fragments

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
~~~
AUTHOR: René Moser (@resmo)
EXTENDS_DOCUMENTATION_FRAGMENT: cloudstack
        METADATA:
          status:
          - stableinterface
~~~



Discussion:
/cc @gundalow 
`2.3.3.0 (stable-2.3 d4ea3c6ca2)` works
probably fixed in  #31677
#31677 includes feature work, so are we happy having this broken in 2.4?
I confirm, #31677 fixes the issue.

Resolving patch:
diff --git a/lib/ansible/utils/plugin_docs.py b/lib/ansible/utils/plugin_docs.py
--- a/lib/ansible/utils/plugin_docs.py
+++ b/lib/ansible/utils/plugin_docs.py
@@ -56,12 +56,13 @@ def merge_fragment(target, source):
                 value = sorted(frozenset(value + target[key]))
             else:
                 raise Exception("Attempt to extend a documentation fragement, invalid type for %s" % key)
+        else:
             target[key] = value
 
 
 def add_fragments(doc, filename):
 
-    fragments = doc.get('extends_documentation_fragment', [])
+    fragments = doc.pop('extends_documentation_fragment', [])
 
     if isinstance(fragments, string_types):
         fragments = [fragments]


Test patch: