Debian Codegraph @

ansible_collections/community/vmware/plugins/modules/vmware_host_config_info.py

raw
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_host_config_info
15 short_description: Gathers info about an ESXi host's advance configuration information
16 description:
17 - This module can be used to gather information about an ESXi host's advance configuration information when ESXi hostname or Cluster name is given.
18 author:
19 - Abhijeet Kasurde (@Akasurde)
20 options:
21 cluster_name:
22 description:
23 - Name of the cluster from which the ESXi host belong to.
24 - If O(esxi_hostname) is not given, this parameter is required.
25 type: str
26 esxi_hostname:
27 description:
28 - ESXi hostname to gather information from.
29 - If O(cluster_name) is not given, this parameter is required.
30 type: str
31 extends_documentation_fragment:
32 - vmware.vmware.base_options
33
34 '''
35
36 EXAMPLES = r'''
37 - name: Gather info about all ESXi Host in given Cluster
38 community.vmware.vmware_host_config_info:
39 hostname: '{{ vcenter_hostname }}'
40 username: '{{ vcenter_username }}'
41 password: '{{ vcenter_password }}'
42 cluster_name: cluster_name
43 delegate_to: localhost
44
45 - name: Gather info about ESXi Host
46 community.vmware.vmware_host_config_info:
47 hostname: '{{ vcenter_hostname }}'
48 username: '{{ vcenter_username }}'
49 password: '{{ vcenter_password }}'
50 esxi_hostname: '{{ esxi_hostname }}'
51 delegate_to: localhost
52 '''
53
54 RETURN = r'''
55 hosts_info:
56 description:
57 - dict with hostname as key and dict with host config information
58 returned: always
59 type: dict
60 sample: {
61 "10.76.33.226": {
62 "Annotations.WelcomeMessage": "",
63 "BufferCache.FlushInterval": 30000,
64 "BufferCache.HardMaxDirty": 95,
65 "BufferCache.PerFileHardMaxDirty": 50,
66 "BufferCache.SoftMaxDirty": 15,
67 }
68 }
69 '''
70
71 from ansible.module_utils.basic import AnsibleModule
72 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi
73 from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec
74
75
76 class VmwareConfigInfoManager(PyVmomi):
77 def __init__(self, module):
78 super(VmwareConfigInfoManager, self).__init__(module)
79 cluster_name = self.params.get('cluster_name', None)
80 esxi_host_name = self.params.get('esxi_hostname', None)
81 self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name)
82
83 def gather_host_info(self):
84 hosts_info = {}
85 for host in self.hosts:
86 host_info = {}
87 for option in host.configManager.advancedOption.QueryOptions():
88 host_info[option.key] = option.value
89 hosts_info[host.name] = host_info
90 return hosts_info
91
92
93 def main():
94 argument_spec = base_argument_spec()
95 argument_spec.update(
96 cluster_name=dict(type='str', required=False),
97 esxi_hostname=dict(type='str', required=False),
98 )
99
100 module = AnsibleModule(
101 argument_spec=argument_spec,
102 required_one_of=[
103 ['cluster_name', 'esxi_hostname'],
104 ],
105 supports_check_mode=True
106 )
107
108 vmware_host_config = VmwareConfigInfoManager(module)
109 module.exit_json(changed=False, hosts_info=vmware_host_config.gather_host_info())
110
111
112 if __name__ == "__main__":
113 main()