diff --git a/plugins/module_utils/hashivault.py b/plugins/module_utils/hashivault.py index 03a1b01..eebfe43 100644 --- a/plugins/module_utils/hashivault.py +++ b/plugins/module_utils/hashivault.py @@ -299,13 +299,13 @@ def _compare_state(desired_state, current_state, ignore=None): if ignore is None: ignore = [] - if type(desired_state) is list: - if (type(current_state) != list) or (len(desired_state) != len(current_state)): + if isinstance(desired_state, list): + if not isinstance(current_state, list) or (len(desired_state) != len(current_state)): return False return set(desired_state) == set(current_state) - if type(desired_state) is dict: - if type(current_state) != dict: + if isinstance(desired_state, dict): + if not isinstance(current_state, dict): return False # iterate over dictionary keys @@ -341,7 +341,7 @@ def _convert_to_seconds(original_value): ray = value.split("s") seconds += int(ray.pop(0)) return seconds - except Exception: # noqa: BLE001 + except Exception: # noqa: BLE001,S110 pass return original_value @@ -376,9 +376,9 @@ def get_keys_updated(desired_state, current_state, ignore=None): continue new_value = desired_state[key] old_value = current_state[key] - if "ttl" in key and (_convert_to_seconds(old_value) != _convert_to_seconds(new_value)): - differences.append(key) - elif not _compare_state(new_value, old_value): + if ( + "ttl" in key and (_convert_to_seconds(old_value) != _convert_to_seconds(new_value)) + ) or not _compare_state(new_value, old_value): differences.append(key) return differences diff --git a/plugins/modules/openssl_pkcs12.py b/plugins/modules/openssl_pkcs12.py index a7ad1a7..39b5ad7 100644 --- a/plugins/modules/openssl_pkcs12.py +++ b/plugins/modules/openssl_pkcs12.py @@ -200,7 +200,7 @@ class Pkcs(object): # noqa def load_privatekey(self, path, passphrase=None): """Load the specified OpenSSL private key.""" try: - privatekey = ( + return ( crypto.load_privatekey( crypto.FILETYPE_PEM, open(path, "rb").read(), # noqa @@ -212,8 +212,6 @@ class Pkcs(object): # noqa open(path, "rb").read(), # noqa ) ) - - return privatekey except OSError as exc: raise PkcsError(exc) from exc @@ -221,8 +219,7 @@ class Pkcs(object): # noqa """Load the specified certificate.""" try: cert_content = open(path, "rb").read() # noqa - cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert_content) - return cert + return crypto.load_certificate(crypto.FILETYPE_PEM, cert_content) except OSError as exc: raise PkcsError(exc) from exc diff --git a/plugins/modules/proxmox_kvm.py b/plugins/modules/proxmox_kvm.py index 19b748c..b117f4f 100644 --- a/plugins/modules/proxmox_kvm.py +++ b/plugins/modules/proxmox_kvm.py @@ -842,8 +842,7 @@ from ansible.module_utils.basic import AnsibleModule, env_fallback def get_nextvmid(module, proxmox): try: - vmid = proxmox.cluster.nextid.get() - return vmid + return proxmox.cluster.nextid.get() except Exception as e: # noqa module.fail_json( msg=f"Unable to get next vmid. Failed with exception: {to_native(e)}", @@ -1331,7 +1330,7 @@ def main(): ) # Ensure source VM name exists when cloning - if -1 == vmid: + if vmid == -1: module.fail_json(msg=f"VM with name = {clone} does not exist in cluster") # Ensure source VM id exists when cloning @@ -1356,7 +1355,7 @@ def main(): ) except Exception as e: # noqa module.fail_json( - vmid=vmid, msg=f"Unable to delete settings on VM {name} with vmid {vmid}: {str(e)}" + vmid=vmid, msg=f"Unable to delete settings on VM {name} with vmid {vmid}: {e!s}" ) if revert is not None: @@ -1369,7 +1368,7 @@ def main(): module.fail_json( vmid=vmid, msg=f"Unable to revert settings on VM {name} with vmid {vmid}:" - f"Maybe is not a pending task...{str(e)}", + f"Maybe is not a pending task...{e!s}", ) if state == "present": @@ -1504,7 +1503,7 @@ def main(): elif state == "started": status = {} try: - if -1 == vmid: + if vmid == -1: module.fail_json(msg=f"VM with name = {name} does not exist in cluster") vm = get_vm(proxmox, vmid) if not vm: @@ -1525,7 +1524,7 @@ def main(): elif state == "stopped": status = {} try: - if -1 == vmid: + if vmid == -1: module.fail_json(msg=f"VM with name = {name} does not exist in cluster") vm = get_vm(proxmox, vmid) @@ -1550,7 +1549,7 @@ def main(): elif state == "restarted": status = {} try: - if -1 == vmid: + if vmid == -1: module.fail_json(msg=f"VM with name = {name} does not exist in cluster") vm = get_vm(proxmox, vmid) @@ -1602,7 +1601,7 @@ def main(): elif state == "current": status = {} - if -1 == vmid: + if vmid == -1: module.fail_json(msg=f"VM with name = {name} does not exist in cluster") vm = get_vm(proxmox, vmid) if not vm: