mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
VMware: new module : vmware_about_facts (#43146)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
551501f326
commit
cc3dadf16e
3 changed files with 215 additions and 0 deletions
124
lib/ansible/modules/cloud/vmware/vmware_about_facts.py
Normal file
124
lib/ansible/modules/cloud/vmware/vmware_about_facts.py
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
|
||||||
|
#
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
ANSIBLE_METADATA = {
|
||||||
|
'metadata_version': '1.1',
|
||||||
|
'status': ['preview'],
|
||||||
|
'supported_by': 'community'
|
||||||
|
}
|
||||||
|
|
||||||
|
DOCUMENTATION = r'''
|
||||||
|
---
|
||||||
|
module: vmware_about_facts
|
||||||
|
short_description: Provides information about VMware server to which user is connecting to
|
||||||
|
description:
|
||||||
|
- This module can be used to gather information about VMware server to which user is trying to connect.
|
||||||
|
version_added: 2.7
|
||||||
|
author:
|
||||||
|
- Abhijeet Kasurde (@Akasurde)
|
||||||
|
notes:
|
||||||
|
- Tested on vSphere 6.5
|
||||||
|
requirements:
|
||||||
|
- python >= 2.6
|
||||||
|
- PyVmomi
|
||||||
|
extends_documentation_fragment: vmware.documentation
|
||||||
|
'''
|
||||||
|
|
||||||
|
EXAMPLES = r'''
|
||||||
|
- name: Provide information about vCenter
|
||||||
|
vmware_about_facts:
|
||||||
|
hostname: '{{ vcenter_hostname }}'
|
||||||
|
username: '{{ vcenter_username }}'
|
||||||
|
password: '{{ vcenter_password }}'
|
||||||
|
register: vcenter_about_info
|
||||||
|
|
||||||
|
- name: Provide information about a standalone ESXi server
|
||||||
|
vmware_about_facts:
|
||||||
|
hostname: '{{ esxi_hostname }}'
|
||||||
|
username: '{{ esxi_username }}'
|
||||||
|
password: '{{ esxu_password }}'
|
||||||
|
register: esxi_about_info
|
||||||
|
'''
|
||||||
|
|
||||||
|
RETURN = r'''
|
||||||
|
about_facts:
|
||||||
|
description:
|
||||||
|
- dict about VMware server
|
||||||
|
returned: success
|
||||||
|
type: string
|
||||||
|
sample:
|
||||||
|
{
|
||||||
|
"api_type": "VirtualCenter",
|
||||||
|
"api_version": "6.5",
|
||||||
|
"build": "5973321",
|
||||||
|
"instance_uuid": "dbed6e0c-bd88-4ef6-b594-21283e1c677f",
|
||||||
|
"license_product_name": "VMware VirtualCenter Server",
|
||||||
|
"license_product_version": "6.0",
|
||||||
|
"locale_build": "000",
|
||||||
|
"locale_version": "INTL",
|
||||||
|
"os_type": "darwin-amd64",
|
||||||
|
"product_full_name": "VMware vCenter Server 6.5.0 build-5973321",
|
||||||
|
"product_line_id": "vpx",
|
||||||
|
"product_name": "VMware vCenter Server (govmomi simulator)",
|
||||||
|
"vendor": "VMware, Inc.",
|
||||||
|
"version": "6.5.0"
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.vmware import vmware_argument_spec, PyVmomi
|
||||||
|
|
||||||
|
|
||||||
|
class VmwareAboutManager(PyVmomi):
|
||||||
|
def __init__(self, module):
|
||||||
|
super(VmwareAboutManager, self).__init__(module)
|
||||||
|
|
||||||
|
def gather_about_facts(self):
|
||||||
|
|
||||||
|
if not self.content:
|
||||||
|
self.module.exit_json(changed=False, about_facts=dict())
|
||||||
|
|
||||||
|
about = self.content.about
|
||||||
|
|
||||||
|
self.module.exit_json(
|
||||||
|
changed=False,
|
||||||
|
about_facts=dict(
|
||||||
|
product_name=about.name,
|
||||||
|
product_full_name=about.fullName,
|
||||||
|
vendor=about.vendor,
|
||||||
|
version=about.version,
|
||||||
|
build=about.build,
|
||||||
|
locale_version=about.localeVersion,
|
||||||
|
locale_build=about.localeBuild,
|
||||||
|
os_type=about.osType,
|
||||||
|
product_line_id=about.productLineId,
|
||||||
|
api_type=about.apiType,
|
||||||
|
api_version=about.apiVersion,
|
||||||
|
instance_uuid=about.instanceUuid,
|
||||||
|
license_product_name=about.licenseProductName,
|
||||||
|
license_product_version=about.licenseProductVersion,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
argument_spec = vmware_argument_spec()
|
||||||
|
|
||||||
|
module = AnsibleModule(
|
||||||
|
argument_spec=argument_spec,
|
||||||
|
supports_check_mode=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
vmware_about_facts_mgr = VmwareAboutManager(module)
|
||||||
|
vmware_about_facts_mgr.gather_about_facts()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
2
test/integration/targets/vmware_about_facts/aliases
Normal file
2
test/integration/targets/vmware_about_facts/aliases
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
shippable/vcenter/group1
|
||||||
|
cloud/vcenter
|
89
test/integration/targets/vmware_about_facts/tasks/main.yml
Normal file
89
test/integration/targets/vmware_about_facts/tasks/main.yml
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# Test code for the vmware_about_facts module.
|
||||||
|
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
- name: store the vcenter container ip
|
||||||
|
set_fact:
|
||||||
|
vcsim: "{{ lookup('env', 'vcenter_host') }}"
|
||||||
|
|
||||||
|
- debug: var=vcsim
|
||||||
|
|
||||||
|
- name: Wait for Flask controller to come up online
|
||||||
|
wait_for:
|
||||||
|
host: "{{ vcsim }}"
|
||||||
|
port: 5000
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: kill vcsim
|
||||||
|
uri:
|
||||||
|
url: http://{{ vcsim }}:5000/killall
|
||||||
|
|
||||||
|
- name: start vcsim
|
||||||
|
uri:
|
||||||
|
url: http://{{ vcsim }}:5000/spawn?cluster=2
|
||||||
|
register: vcsim_instance
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: vcsim_instance
|
||||||
|
|
||||||
|
- name: Wait for vcsim server to come up online
|
||||||
|
wait_for:
|
||||||
|
host: "{{ vcsim }}"
|
||||||
|
port: 443
|
||||||
|
state: started
|
||||||
|
|
||||||
|
|
||||||
|
- name: Get Details about VMware vCenter Server
|
||||||
|
vmware_about_facts:
|
||||||
|
hostname: "{{ vcsim }}"
|
||||||
|
username: "{{ vcsim_instance.json.username }}"
|
||||||
|
password: "{{ vcsim_instance.json.password }}"
|
||||||
|
validate_certs: no
|
||||||
|
register: about
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- about.about_facts["{{ item }}"] is defined
|
||||||
|
with_items:
|
||||||
|
- api_type
|
||||||
|
- api_version
|
||||||
|
- build
|
||||||
|
- instance_uuid
|
||||||
|
- license_product_name
|
||||||
|
- license_product_version
|
||||||
|
- locale_build
|
||||||
|
- locale_version
|
||||||
|
- os_type
|
||||||
|
- product_full_name
|
||||||
|
- product_line_id
|
||||||
|
- product_name
|
||||||
|
- vendor
|
||||||
|
- version
|
||||||
|
|
||||||
|
- name: Get Details about VMware vCenter Server in check mode
|
||||||
|
vmware_about_facts:
|
||||||
|
hostname: "{{ vcsim }}"
|
||||||
|
username: "{{ vcsim_instance.json.username }}"
|
||||||
|
password: "{{ vcsim_instance.json.password }}"
|
||||||
|
validate_certs: no
|
||||||
|
register: about
|
||||||
|
check_mode: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- about.about_facts["{{ item }}"] is defined
|
||||||
|
with_items:
|
||||||
|
- api_type
|
||||||
|
- api_version
|
||||||
|
- build
|
||||||
|
- instance_uuid
|
||||||
|
- license_product_name
|
||||||
|
- license_product_version
|
||||||
|
- locale_build
|
||||||
|
- locale_version
|
||||||
|
- os_type
|
||||||
|
- product_full_name
|
||||||
|
- product_line_id
|
||||||
|
- product_name
|
||||||
|
- vendor
|
||||||
|
- version
|
Loading…
Reference in a new issue