Repository: ansible-collections/community.vmware

Issue:
vmware_content_library_info: Only lists Content Libraries with the type of "Local", does not include "Subscribed" type
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
When using the vmware_content_library_info task type to query our Content Libraries, only the Libraries with the type of "Local" are reported back to the ansible task. We used shared or "Subscribed" Content Libraries in our environment, to share a consistent Library of VM Templates between all of our vCenters.

How can we get this functionality added?

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
vmware_content_library_info

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.10.9
  config file = /home/<redacted>/.ansible.cfg
  configured module search path = ['/home/<redacted>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/<redacted>/.local/lib/python3.8/site-packages/ansible
  executable location = /home/<redacted>/.local/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
```

##### COLLECTION VERSION
<!--- Paste verbatim output from "ansible-galaxy collection list <namespace>.<collection>"  between the quotes
for example: ansible-galaxy collection list community.general
-->
```paste below

# /usr/local/lib/python3.8/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.10.0

# /home/<redacted>/.local/lib/python3.8/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.10.0
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
DEFAULT_HOST_LIST(/home/<redacted>/.ansible.cfg) = ['/home/<redacted>/inventory']
DEFAULT_LOG_PATH(/home/<redacted>/.ansible.cfg) = /home/<redacted>/.ansible/logs/log.txt
DEFAULT_TIMEOUT(/home/<redacted>/.ansible.cfg) = 120
DEFAULT_VAULT_PASSWORD_FILE(/home/<redacted>/.ansible.cfg) = /home/<redacted>/playbooks/secret.yaml
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
vCenter Version - 7.0.3 build 20150588
Client - vSphere Client version 7.0.3.00700
Hosts - VMware ESXi, 7.0.3, 20036589

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
    - name: "Collect list of Content Libraries from specified vCenter"
      community.vmware.vmware_content_library_info:
        hostname: "{{ hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        validate_certs: no
      register: libraries

    - name: "Display list of found Content Libraries"
      debug:
        var: libraries
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
```yaml
TASK [Display list of found Content Libraries] ****************************************************************************************************************************
ok: [localhost] => {
    "libraries": {
        "changed": false,
        "content_libs": [
            "6b5e0c60-3173-4a75-8101-33335f3bb7dd",
            "7bd40369-84d6-4fd5-9cf9-7c33377f3931"
        ],
        "failed": false
    }
}
```

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```yaml
TASK [Display list of found Content Libraries] ****************************************************************************************************************************
ok: [localhost] => {
    "libraries": {
        "changed": false,
        "content_libs": [
            "6b5e0c60-3173-4a75-8101-33335f3bb7dd"
        ],
        "failed": false
    }
}
```



Discussion:
1.10.0 is quite old...

However, it looks like `vmware_content_library_info` still doesn't know about subscribed content libraries in the latest release. I'll try to work on this, but you probably would have to update to (at least) `community.vmware` 2.9.0.

_edit:_ I think we could use the [Content Subscribed Library APIs](https://developer.vmware.com/apis/vsphere-automation/latest/content/content/subscribed_library/) to achieve this.

Resolving patch:
diff --git a/plugins/modules/vmware_content_library_info.py b/plugins/modules/vmware_content_library_info.py
--- a/plugins/modules/vmware_content_library_info.py
+++ b/plugins/modules/vmware_content_library_info.py
@@ -93,25 +93,46 @@ def __init__(self, module):
         """Constructor."""
         super(VmwareContentLibInfo, self).__init__(module)
         self.content_service = self.api_client
+        self.local_content_libraries = self.content_service.content.LocalLibrary.list()
+        if self.local_content_libraries is None:
+            self.local_content_libraries = []
+
+        self.subscribed_content_libraries = self.content_service.content.SubscribedLibrary.list()
+        if self.subscribed_content_libraries is None:
+            self.subscribed_content_libraries = []
+
         self.library_info = []
 
     def get_all_content_libs(self):
         """Method to retrieve List of content libraries."""
-        self.module.exit_json(changed=False, content_libs=self.content_service.content.LocalLibrary.list())
+        content_libraries = self.local_content_libraries + self.subscribed_content_libraries
+
+        self.module.exit_json(changed=False, content_libs=content_libraries)
 
     def get_content_lib_details(self, library_id):
         """Method to retrieve Details of contentlib with library_id"""
-        try:
-            lib_details = self.content_service.content.LocalLibrary.get(library_id)
-        except Exception as e:
-            self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
-        lib_publish_info = dict(
-            persist_json_enabled=lib_details.publish_info.persist_json_enabled,
-            authentication_method=lib_details.publish_info.authentication_method,
-            publish_url=lib_details.publish_info.publish_url,
-            published=lib_details.publish_info.published,
-            user_name=lib_details.publish_info.user_name
-        )
+        lib_publish_info = None
+
+        if library_id in self.local_content_libraries:
+            try:
+                lib_details = self.content_service.content.LocalLibrary.get(library_id)
+                lib_publish_info = dict(
+                    persist_json_enabled=lib_details.publish_info.persist_json_enabled,
+                    authentication_method=lib_details.publish_info.authentication_method,
+                    publish_url=lib_details.publish_info.publish_url,
+                    published=lib_details.publish_info.published,
+                    user_name=lib_details.publish_info.user_name
+                )
+            except Exception as e:
+                self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
+        elif library_id in self.subscribed_content_libraries:
+            try:
+                lib_details = self.content_service.content.SubscribedLibrary.get(library_id)
+            except Exception as e:
+                self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
+        else:
+            self.module.fail_json(exists=False, msg="Library %s not found." % library_id)
+
         self.library_info.append(
             dict(
                 library_name=lib_details.name,


Test patch: