diff --git a/plugins/inventory_utils/_base.py b/plugins/inventory_utils/_base.py index 1dd27c6f..b19268d8 100644 --- a/plugins/inventory_utils/_base.py +++ b/plugins/inventory_utils/_base.py @@ -65,9 +65,9 @@ def initialize_rest_client(self, config_data): def get_credentials_from_options(self): """ The username and password options can be plain text, jinja templates, or encrypted strings. - This method handles these different options and returns a plain text version of username and password + This method handles these different options and returns a plain text version of the username and password Returns: - A tuple of plain text username and password + A tuple of the plain text username and password """ username = self.get_option("username") password = self.get_option("password") @@ -137,11 +137,11 @@ def update_cached_result(self, cache, cache_key, result): def get_objects_by_type(self, vim_type): """ Searches the requested search paths for objects of type vim_type. If the search path - doesn't actually exist, continue. If no search path is give, check everywhere + doesn't actually exist, continue. If no search path is given, check everywhere Args: vim_type: The vim object type. It should be given as a list, like [vim.HostSystem] Returns: - List of objects that exist in the search path(s) and match vim type + List of objects that exist in the search path(s) and match the vim type """ if not self.get_option('search_paths'): return self.pyvmomi_client.get_all_objs_by_type(vimtype=vim_type) @@ -159,7 +159,7 @@ def gather_tags(self, object_moid): """ Given an object moid, gather any tags attached to the object. Args: - object_moid: str, The objects MOID + object_moid: str, The object's MOID Returns: tuple First item is a dict with the object's tags. Keys are tag IDs and values are tag names diff --git a/plugins/module_utils/clients/_pyvmomi.py b/plugins/module_utils/clients/_pyvmomi.py index 5d58c2dc..5f2e5e31 100644 --- a/plugins/module_utils/clients/_pyvmomi.py +++ b/plugins/module_utils/clients/_pyvmomi.py @@ -41,7 +41,7 @@ def __init__(self, connection_params): def connect_to_api(self, connection_params, disconnect_atexit=True, return_si=False): """ Connect to the vCenter/ESXi client using the pyvmomi SDK. This creates a service instance - which can then be used programmatically to make calls to vCenter or ESXi + which can then be used programmatically to make calls to the vCenter or ESXi Args: connection_params: dict, A dictionary with different authentication or connection parameters like username, password, hostname, etc. The full list is found in the method below. @@ -157,18 +157,18 @@ def __create_service_instance(self, connection_args, username, password, http_pr service_instance = connect.SmartConnect(**connection_args) except vim.fault.InvalidLogin as e: raise ApiAccessError(( - "Unable to log on to vCenter or ESXi API at %s:%s as %s: %s" % + "Unable to log on to the vCenter or ESXi API at %s:%s as %s: %s" % (connection_args['host'], connection_args['port'], username, e.msg) + error_msg_suffix )) except vim.fault.NoPermission as e: raise ApiAccessError(( - "User %s does not have required permission to log on to vCenter or ESXi API at %s:%s : %s" % + "User %s does not have the required permissions to log on to the vCenter or ESXi API at %s:%s : %s" % (username, connection_args['host'], connection_args['port'], e.msg) )) except (requests.ConnectionError, ssl.SSLError) as e: raise ApiAccessError(( - "Unable to connect to vCenter or ESXi API at %s on TCP/%s: %s" % + "Unable to connect to the vCenter or ESXi API at %s on TCP/%s: %s" % (connection_args['host'], connection_args['port'], e) )) except vmodl.fault.InvalidRequest as e: @@ -179,14 +179,14 @@ def __create_service_instance(self, connection_args, username, password, http_pr )) except Exception as e: raise ApiAccessError(( - "Unknown error while connecting to vCenter or ESXi API at %s:%s : %s" % + "Unknown error while connecting to the vCenter or ESXi API at %s:%s : %s" % (connection_args['host'], connection_args['port'], e.msg) + error_msg_suffix )) if service_instance is None: raise ApiAccessError(( - "Unknown error while connecting to vCenter or ESXi API at %s:%s" % + "Unknown error while connecting to the vCenter or ESXi API at %s:%s" % (connection_args['host'], connection_args['port']) + error_msg_suffix )) @@ -204,7 +204,7 @@ def check_requirements(self): def get_all_objs_by_type(self, vimtype, folder=None, recurse=True): """ - Returns a list of all objects matching a given VMWare type. + Returns a list of all objects matching a given VMware type. You can also limit the search by folder and recurse if desired Args: vimtype: The type of object to search for @@ -212,7 +212,7 @@ def get_all_objs_by_type(self, vimtype, folder=None, recurse=True): none is provided, the datacenter root will be used recurse: If true, the search will recurse through the folder structure Returns: - list of objs + A list of matching objects. """ if not folder: folder = self.content.rootFolder diff --git a/plugins/module_utils/clients/_rest.py b/plugins/module_utils/clients/_rest.py index 6ac54560..e766a1ff 100644 --- a/plugins/module_utils/clients/_rest.py +++ b/plugins/module_utils/clients/_rest.py @@ -164,7 +164,7 @@ def get_tags_by_vm_moid(self, vm_moid): vm_moid: the VM MOID to use to gather tags Returns: - List of tag object associated with the given virtual machine + List of tag objects associated with the given virtual machine """ dobj = DynamicID(type='VirtualMachine', id=vm_moid) return self.get_tags_for_dynamic_id_obj(dobj=dobj) @@ -176,14 +176,14 @@ def get_tags_by_host_moid(self, host_moid): host_moid: the Host MOID to use to gather tags Returns: - List of tag object associated with the given host + List of tag objects associated with the given host """ dobj = DynamicID(type='HostSystem', id=host_moid) return self.get_tags_for_dynamic_id_obj(dobj=dobj) def get_tags_for_dynamic_id_obj(self, dobj): """ - Return tag objects associated with an DynamicID object. + Return tag objects associated with a DynamicID object. Args: dobj: Dynamic object Returns: diff --git a/tests/integration/targets/vmware_inventory_esxi_hosts/files/test.esxi_hosts.yml b/tests/integration/targets/vmware_inventory_esxi_hosts/files/test.esxi_hosts.yml index 00b5173c..077a7f71 100644 --- a/tests/integration/targets/vmware_inventory_esxi_hosts/files/test.esxi_hosts.yml +++ b/tests/integration/targets/vmware_inventory_esxi_hosts/files/test.esxi_hosts.yml @@ -1,5 +1,11 @@ --- plugin: vmware.vmware.esxi_hosts + +hostname: "{{ vcenter_hostname }}" +username: "{{ vcenter_username }}" +password: "{{ vcenter_password }}" +port: "{{ vcenter_port }}" + cache: false group_by_paths: true group_by_paths_prefix: test diff --git a/tests/integration/targets/vmware_inventory_esxi_hosts/tasks/main.yml b/tests/integration/targets/vmware_inventory_esxi_hosts/tasks/main.yml index 74b8f689..8c7c5baf 100644 --- a/tests/integration/targets/vmware_inventory_esxi_hosts/tasks/main.yml +++ b/tests/integration/targets/vmware_inventory_esxi_hosts/tasks/main.yml @@ -8,22 +8,23 @@ ansible.builtin.command: ansible-inventory -i "{{ role_path }}/files/test.esxi_hosts.yml" --list register: _inventory_out - - name: Debug Inventory Output - ansible.builtin.debug: - var: _inventory_out - - name: Parse Inventory Results as JSON ansible.builtin.set_fact: inventory_results: "{{ _inventory_out.stdout | from_json }}" + - name: Debug Inventory Output Because It Failed + ansible.builtin.debug: + var: _inventory_out + when: not inventory_results._meta.hostvars + # you can't reference the 'all' property here for some reason. It reverts back to the test playbook inventory # instead of the inventory_results - name: Check Output ansible.builtin.assert: that: - - first_host.ansible_host - - first_host.tags is defined - - first_host.tags_by_category is defined + - first_host.ansible_host is regex('^[\d+\.]+$') + - first_host.tags is defined and first_host.tags is not None + - first_host.tags_by_category is defined and first_host.tags_by_category is not None - >- (inventory_results.poweredOn.hosts | length) == (inventory_results._meta.hostvars.values() | selectattr('summary.runtime.powerState', 'equalto', 'poweredOn') | length)