33
33
type: str
34
34
state:
35
35
description:
36
- - Set or list acceptance level of the given ESXi host.
37
- - 'If set to C(list), then will return current acceptance level of given host system/s.'
38
- - If set to C(present), then will set given acceptance level.
39
- choices: [ list, present ]
40
- required: false
41
- default: 'list'
42
- type: str
43
- acceptance_level:
44
- description:
45
- - Name of acceptance level.
46
36
- If set to C(partner), then accept only partner and VMware signed and certified VIBs.
47
37
- If set to C(vmware_certified), then accept only VIBs that are signed and certified by VMware.
48
38
- If set to C(vmware_accepted), then accept VIBs that have been accepted by VMware.
49
39
- If set to C(community), then accept all VIBs, even those that are not signed.
50
40
choices: [ community, partner, vmware_accepted, vmware_certified ]
51
- required: false
41
+ required: true
52
42
type: str
53
43
extends_documentation_fragment:
54
44
- community.vmware.vmware.documentation
62
52
username: '{{ vcenter_username }}'
63
53
password: '{{ vcenter_password }}'
64
54
cluster_name: cluster_name
65
- acceptance_level: 'community'
66
- state: present
55
+ state: 'community'
67
56
delegate_to: localhost
68
57
register: cluster_acceptance_level
69
58
73
62
username: '{{ vcenter_username }}'
74
63
password: '{{ vcenter_password }}'
75
64
esxi_hostname: '{{ esxi_hostname }}'
76
- acceptance_level: 'vmware_accepted'
77
- state: present
78
- delegate_to: localhost
79
- register: host_acceptance_level
80
-
81
- - name: Get acceptance level from the given ESXi Host
82
- community.vmware.vmware_host_acceptance:
83
- hostname: '{{ vcenter_hostname }}'
84
- username: '{{ vcenter_username }}'
85
- password: '{{ vcenter_password }}'
86
- esxi_hostname: '{{ esxi_hostname }}'
87
- state: list
65
+ state: 'vmware_accepted'
88
66
delegate_to: localhost
89
67
register: host_acceptance_level
90
68
'''
@@ -115,9 +93,9 @@ def __init__(self, module):
115
93
self .hosts = self .get_all_host_objs (cluster_name = cluster_name , esxi_host_name = esxi_host_name )
116
94
self .desired_state = self .params .get ('state' )
117
95
self .hosts_facts = {}
118
- self .acceptance_level = self .params .get ('acceptance_level' )
119
96
120
- def gather_acceptance_facts (self ):
97
+ def set_acceptance_level (self ):
98
+ change = []
121
99
for host in self .hosts :
122
100
self .hosts_facts [host .name ] = dict (level = '' , error = 'NA' )
123
101
host_image_config_mgr = host .configManager .imageConfigManager
@@ -126,60 +104,43 @@ def gather_acceptance_facts(self):
126
104
self .hosts_facts [host .name ]['level' ] = host_image_config_mgr .HostImageConfigGetAcceptance ()
127
105
except vim .fault .HostConfigFault as e :
128
106
self .hosts_facts [host .name ]['error' ] = to_native (e .msg )
129
-
130
- def set_acceptance_level (self ):
131
- change = []
132
- for host in self .hosts :
133
107
host_changed = False
134
- if self .hosts_facts [host .name ]['level' ] != self .acceptance_level :
135
- host_image_config_mgr = host .configManager .imageConfigManager
136
- if host_image_config_mgr :
137
- try :
138
- if self .module .check_mode :
139
- self .hosts_facts [host .name ]['level' ] = self .acceptance_level
140
- else :
141
- host_image_config_mgr .UpdateHostImageAcceptanceLevel (newAcceptanceLevel = self .acceptance_level )
142
- self .hosts_facts [host .name ]['level' ] = host_image_config_mgr .HostImageConfigGetAcceptance ()
143
- host_changed = True
144
- except vim .fault .HostConfigFault as e :
145
- self .hosts_facts [host .name ]['error' ] = to_native (e .msg )
108
+ if self .hosts_facts [host .name ]['level' ] != self .desired_state :
109
+ try :
110
+ if self .module .check_mode :
111
+ self .hosts_facts [host .name ]['level' ] = self .desired_state
112
+ else :
113
+ host_image_config_mgr .UpdateHostImageAcceptanceLevel (newAcceptanceLevel = self .desired_state )
114
+ self .hosts_facts [host .name ]['level' ] = host_image_config_mgr .HostImageConfigGetAcceptance ()
115
+ host_changed = True
116
+ except vim .fault .HostConfigFault as e :
117
+ self .hosts_facts [host .name ]['error' ] = to_native (e .msg )
146
118
147
119
change .append (host_changed )
148
120
self .module .exit_json (changed = any (change ), facts = self .hosts_facts )
149
121
150
- def check_acceptance_state (self ):
151
- self .gather_acceptance_facts ()
152
- if self .desired_state == 'list' :
153
- self .module .exit_json (changed = False , facts = self .hosts_facts )
154
- self .set_acceptance_level ()
155
-
156
122
157
123
def main ():
158
124
argument_spec = vmware_argument_spec ()
159
125
argument_spec .update (
160
126
cluster_name = dict (type = 'str' , required = False ),
161
127
esxi_hostname = dict (type = 'str' , required = False ),
162
- acceptance_level = dict (type = 'str' ,
163
- choices = ['community' , 'partner' , 'vmware_accepted' , 'vmware_certified' ]
164
- ),
165
128
state = dict (type = 'str' ,
166
- choices = ['list' , 'present' ],
167
- default = 'list' ),
129
+ choices = ['community' , 'partner' , 'vmware_accepted' , 'vmware_certified' ],
130
+ required = True
131
+ ),
168
132
)
169
133
170
134
module = AnsibleModule (
171
135
argument_spec = argument_spec ,
172
136
required_one_of = [
173
137
['cluster_name' , 'esxi_hostname' ],
174
138
],
175
- required_if = [
176
- ['state' , 'present' , ['acceptance_level' ]],
177
- ],
178
139
supports_check_mode = True
179
140
)
180
141
181
142
vmware_host_accept_config = VMwareAccpetanceManager (module )
182
- vmware_host_accept_config .check_acceptance_state ()
143
+ vmware_host_accept_config .set_acceptance_level ()
183
144
184
145
185
146
if __name__ == "__main__" :
0 commit comments