mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
VMware: check for ESXi server while creating user (#33061)
This fix check for ESXi server instance before proceeding with managing local user. Also, adds integration tests for this change. Fixes: #32465 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
31510259f6
commit
29d3505cb4
10 changed files with 183 additions and 24 deletions
|
@ -1233,6 +1233,11 @@ class PyVmomiHelper(PyVmomi):
|
|||
if current_parent.name == parent.name:
|
||||
return True
|
||||
|
||||
# Check if we have reached till root folder
|
||||
moid = current_parent._moId
|
||||
if moid in ['group-d1', 'ha-folder-root']:
|
||||
return False
|
||||
|
||||
current_parent = current_parent.parent
|
||||
if current_parent is None:
|
||||
return False
|
||||
|
|
|
@ -10,9 +10,11 @@ from __future__ import absolute_import, division, print_function
|
|||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
ANSIBLE_METADATA = {
|
||||
'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'
|
||||
}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
|
@ -32,15 +34,15 @@ requirements:
|
|||
options:
|
||||
local_user_name:
|
||||
description:
|
||||
- The local user name to be changed
|
||||
- The local user name to be changed.
|
||||
required: True
|
||||
local_user_password:
|
||||
description:
|
||||
- The password to be set
|
||||
- The password to be set.
|
||||
required: False
|
||||
local_user_description:
|
||||
description:
|
||||
- Description for the user
|
||||
- Description for the user.
|
||||
required: False
|
||||
state:
|
||||
description:
|
||||
|
@ -65,24 +67,28 @@ RETURN = '''# '''
|
|||
|
||||
try:
|
||||
from pyVmomi import vim, vmodl
|
||||
HAS_PYVMOMI = True
|
||||
except ImportError:
|
||||
HAS_PYVMOMI = False
|
||||
pass
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.vmware import HAS_PYVMOMI, connect_to_api, vmware_argument_spec
|
||||
from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec
|
||||
|
||||
|
||||
class VMwareLocalUserManager(object):
|
||||
class VMwareLocalUserManager(PyVmomi):
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.content = connect_to_api(self.module)
|
||||
super(VMwareLocalUserManager, self).__init__(module)
|
||||
self.local_user_name = self.module.params['local_user_name']
|
||||
self.local_user_password = self.module.params['local_user_password']
|
||||
self.local_user_description = self.module.params['local_user_description']
|
||||
self.state = self.module.params['state']
|
||||
|
||||
if self.is_vcenter():
|
||||
self.module.fail_json(msg="Failed to get local account manager settings "
|
||||
"from ESXi server: %s" % self.module.params['hostname'],
|
||||
details="It seems that %s is a vCenter server instead of an "
|
||||
"ESXi server" % self.module.params['hostname'])
|
||||
|
||||
def process_state(self):
|
||||
try:
|
||||
local_account_manager_states = {
|
||||
|
@ -162,17 +168,14 @@ class VMwareLocalUserManager(object):
|
|||
|
||||
|
||||
def main():
|
||||
|
||||
argument_spec = vmware_argument_spec()
|
||||
argument_spec.update(dict(local_user_name=dict(required=True, type='str'),
|
||||
local_user_password=dict(required=False, type='str', no_log=True),
|
||||
local_user_description=dict(required=False, type='str'),
|
||||
local_user_password=dict(type='str', no_log=True),
|
||||
local_user_description=dict(type='str'),
|
||||
state=dict(default='present', choices=['present', 'absent'], type='str')))
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)
|
||||
|
||||
if not HAS_PYVMOMI:
|
||||
module.fail_json(msg='pyvmomi is required for this module')
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=False)
|
||||
|
||||
vmware_local_user_manager = VMwareLocalUserManager(module)
|
||||
vmware_local_user_manager.process_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue