Debian Codegraph @

ansible_collections/community/vmware/plugins/modules/vmware_host_feature_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_feature_info
15 short_description: Gathers info about an ESXi host's feature capability information
16 description:
17 - This module can be used to gather information about an ESXi host's feature capability 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 all host systems to be used for information gathering.
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 feature capability info about all ESXi Hosts in given Cluster
38 community.vmware.vmware_host_feature_info:
39 hostname: '{{ vcenter_hostname }}'
40 username: '{{ vcenter_username }}'
41 password: '{{ vcenter_password }}'
42 cluster_name: '{{ cluster_name }}'
43 delegate_to: localhost
44 register: all_cluster_hosts_info
45
46 - name: Check if ESXi is vulnerable for Speculative Store Bypass Disable (SSBD) vulnerability
47 community.vmware.vmware_host_feature_info:
48 hostname: "{{ vcenter_hostname }}"
49 username: "{{ vcenter_username }}"
50 password: "{{ vcenter_password }}"
51 esxi_hostname: "{{ esxi_hostname }}"
52 register: features_set
53 - set_fact:
54 ssbd : "{{ item.value }}"
55 loop: "{{ features_set.host_feature_info[esxi_hostname] |json_query(name) }}"
56 vars:
57 name: "[?key=='cpuid.SSBD']"
58 - assert:
59 that:
60 - ssbd|int == 1
61 when: ssbd is defined
62 '''
63
64 RETURN = r'''
65 hosts_feature_info:
66 description: metadata about host's feature capability information
67 returned: always
68 type: dict
69 sample: {
70 "10.76.33.226": [
71 {
72 "feature_name": "cpuid.3DNOW",
73 "key": "cpuid.3DNOW",
74 "value": "0"
75 },
76 {
77 "feature_name": "cpuid.3DNOWPLUS",
78 "key": "cpuid.3DNOWPLUS",
79 "value": "0"
80 },
81 ]
82 }
83 '''
84
85 from ansible.module_utils.basic import AnsibleModule
86 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi
87 from ansible_collections.vmware.vmware.plugins.module_utils.argument_spec import base_argument_spec
88
89
90 class FeatureCapabilityInfoManager(PyVmomi):
91 def __init__(self, module):
92 super(FeatureCapabilityInfoManager, self).__init__(module)
93 cluster_name = self.params.get('cluster_name', None)
94 esxi_host_name = self.params.get('esxi_hostname', None)
95 self.hosts = self.get_all_host_objs(cluster_name=cluster_name, esxi_host_name=esxi_host_name)
96
97 def gather_host_feature_info(self):
98 host_feature_info = dict()
99 for host in self.hosts:
100 host_feature_capabilities = host.config.featureCapability
101 capability = []
102 for fc in host_feature_capabilities:
103 temp_dict = {
104 'key': fc.key,
105 'feature_name': fc.featureName,
106 'value': fc.value,
107 }
108 capability.append(temp_dict)
109
110 host_feature_info[host.name] = capability
111
112 return host_feature_info
113
114
115 def main():
116 argument_spec = base_argument_spec()
117 argument_spec.update(
118 cluster_name=dict(type='str', required=False),
119 esxi_hostname=dict(type='str', required=False),
120 )
121
122 module = AnsibleModule(
123 argument_spec=argument_spec,
124 required_one_of=[
125 ['cluster_name', 'esxi_hostname'],
126 ],
127 supports_check_mode=True,
128 )
129
130 host_capability_manager = FeatureCapabilityInfoManager(module)
131 module.exit_json(changed=False,
132 hosts_feature_info=host_capability_manager.gather_host_feature_info())
133
134
135 if __name__ == "__main__":
136 main()