| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = r''' |
| 13 |
--- |
| 14 |
module: vmware_about_info |
| 15 |
short_description: Provides information about VMware server to which user is connecting to |
| 16 |
description: |
| 17 |
- This module can be used to gather information about VMware server to which user is trying to connect. |
| 18 |
author: |
| 19 |
- Abhijeet Kasurde (@Akasurde) |
| 20 |
extends_documentation_fragment: |
| 21 |
- vmware.vmware.base_options |
| 22 |
|
| 23 |
''' |
| 24 |
|
| 25 |
EXAMPLES = r''' |
| 26 |
- name: Provide information about vCenter |
| 27 |
community.vmware.vmware_about_info: |
| 28 |
hostname: '{{ vcenter_hostname }}' |
| 29 |
username: '{{ vcenter_username }}' |
| 30 |
password: '{{ vcenter_password }}' |
| 31 |
delegate_to: localhost |
| 32 |
register: vcenter_about_info |
| 33 |
|
| 34 |
- name: Provide information about a standalone ESXi server |
| 35 |
community.vmware.vmware_about_info: |
| 36 |
hostname: '{{ esxi_hostname }}' |
| 37 |
username: '{{ esxi_username }}' |
| 38 |
password: '{{ esxi_password }}' |
| 39 |
delegate_to: localhost |
| 40 |
register: esxi_about_info |
| 41 |
''' |
| 42 |
|
| 43 |
RETURN = r''' |
| 44 |
about_info: |
| 45 |
description: |
| 46 |
- dict about VMware server |
| 47 |
returned: success |
| 48 |
type: str |
| 49 |
sample: |
| 50 |
{ |
| 51 |
"api_type": "VirtualCenter", |
| 52 |
"api_version": "6.5", |
| 53 |
"build": "5973321", |
| 54 |
"instance_uuid": "dbed6e0c-bd88-4ef6-b594-21283e1c677f", |
| 55 |
"license_product_name": "VMware VirtualCenter Server", |
| 56 |
"license_product_version": "6.0", |
| 57 |
"locale_build": "000", |
| 58 |
"locale_version": "INTL", |
| 59 |
"os_type": "darwin-amd64", |
| 60 |
"product_full_name": "VMware vCenter Server 6.5.0 build-5973321", |
| 61 |
"product_line_id": "vpx", |
| 62 |
"product_name": "VMware vCenter Server (govmomi simulator)", |
| 63 |
"vendor": "VMware, Inc.", |
| 64 |
"version": "6.5.0" |
| 65 |
} |
| 66 |
''' |
| 67 |
|
| 68 |
from ansible.module_utils.basic import AnsibleModule |
| 69 |
from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi |
| 70 |
from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec |
| 71 |
|
| 72 |
|
| 73 |
class VmwareAboutManager(PyVmomi): |
| 74 |
def __init__(self, module): |
| 75 |
super(VmwareAboutManager, self).__init__(module) |
| 76 |
|
| 77 |
def gather_about_info(self): |
| 78 |
|
| 79 |
if not self.content: |
| 80 |
self.module.exit_json(changed=False, about_info=dict()) |
| 81 |
|
| 82 |
about = self.content.about |
| 83 |
|
| 84 |
self.module.exit_json( |
| 85 |
changed=False, |
| 86 |
about_info=dict( |
| 87 |
product_name=about.name, |
| 88 |
product_full_name=about.fullName, |
| 89 |
vendor=about.vendor, |
| 90 |
version=about.version, |
| 91 |
build=about.build, |
| 92 |
locale_version=about.localeVersion, |
| 93 |
locale_build=about.localeBuild, |
| 94 |
os_type=about.osType, |
| 95 |
product_line_id=about.productLineId, |
| 96 |
api_type=about.apiType, |
| 97 |
api_version=about.apiVersion, |
| 98 |
instance_uuid=about.instanceUuid, |
| 99 |
license_product_name=about.licenseProductName, |
| 100 |
license_product_version=about.licenseProductVersion, |
| 101 |
) |
| 102 |
) |
| 103 |
|
| 104 |
|
| 105 |
def main(): |
| 106 |
argument_spec = base_argument_spec() |
| 107 |
|
| 108 |
module = AnsibleModule( |
| 109 |
argument_spec=argument_spec, |
| 110 |
supports_check_mode=True, |
| 111 |
) |
| 112 |
|
| 113 |
vmware_about_info_mgr = VmwareAboutManager(module) |
| 114 |
vmware_about_info_mgr.gather_about_info() |
| 115 |
|
| 116 |
|
| 117 |
if __name__ == "__main__": |
| 118 |
main() |