From 93d23cfef67dcac23bd7b7a435de65e425c117f7 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:32:10 +0100 Subject: [PATCH] [PR #11119/41923e43 backport][stable-12] fix ruff case SIM103 (#11132) fix ruff case SIM103 (#11119) * fix ruff case SIM103 * add changelog frag (cherry picked from commit 41923e43bd4c5f7484b742d6d19723ceb03495a8) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- changelogs/fragments/11119-ruff-cases-2.yml | 38 +++++++++++++++++++ plugins/lookup/merge_variables.py | 5 +-- plugins/module_utils/_mount.py | 4 +- plugins/module_utils/xenserver.py | 10 +---- plugins/modules/aerospike_migrations.py | 20 +++------- plugins/modules/apk.py | 13 ++----- plugins/modules/apt_rpm.py | 9 +---- plugins/modules/awall.py | 4 +- plugins/modules/beadm.py | 5 +-- plugins/modules/crypttab.py | 8 +--- plugins/modules/gitlab_group_access_token.py | 4 +- .../modules/gitlab_project_access_token.py | 4 +- plugins/modules/hg.py | 14 ++----- plugins/modules/icinga2_host.py | 4 +- plugins/modules/jenkins_job.py | 4 +- plugins/modules/logentries.py | 5 +-- plugins/modules/macports.py | 10 +---- plugins/modules/oneandone_firewall_policy.py | 16 ++------ plugins/modules/oneandone_load_balancer.py | 16 ++------ .../modules/oneandone_monitoring_policy.py | 32 ++++------------ plugins/modules/oneandone_private_network.py | 4 +- plugins/modules/pamd.py | 20 +++------- plugins/modules/parted.py | 5 +-- plugins/modules/redhat_subscription.py | 18 +++------ plugins/modules/riak.py | 5 +-- plugins/modules/slack.py | 4 +- plugins/modules/slackpkg.py | 5 +-- plugins/modules/solaris_zone.py | 5 +-- plugins/modules/svr4pkg.py | 5 +-- plugins/modules/swupd.py | 5 +-- plugins/modules/urpmi.py | 5 +-- plugins/modules/vertica_configuration.py | 4 +- plugins/modules/vertica_role.py | 4 +- plugins/modules/vertica_schema.py | 4 +- plugins/modules/vertica_user.py | 13 ++++--- plugins/modules/xbps.py | 5 +-- plugins/modules/xml.py | 4 +- plugins/modules/zfs.py | 4 +- ruff.toml | 1 - 39 files changed, 115 insertions(+), 230 deletions(-) create mode 100644 changelogs/fragments/11119-ruff-cases-2.yml diff --git a/changelogs/fragments/11119-ruff-cases-2.yml b/changelogs/fragments/11119-ruff-cases-2.yml new file mode 100644 index 0000000000..3e8661db35 --- /dev/null +++ b/changelogs/fragments/11119-ruff-cases-2.yml @@ -0,0 +1,38 @@ +minor_changes: + - merge_variables lookup plugin - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - _mount module utils - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - xenserver module utils - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - aerospike_migrations - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - apk - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - apt_rpm - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - awall - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - beadm - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - crypttab - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - gitlab_group_access_token - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - gitlab_project_access_token - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - hg - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - icinga2_host - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - jenkins_job - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - logentries - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - macports - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - oneandone_firewall_policy - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - oneandone_load_balancer - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - oneandone_monitoring_policy - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - oneandone_private_network - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - pamd - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - parted - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - redhat_subscription - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - riak - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - slack - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - slackpkg - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - solaris_zone - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - svr4pkg - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - swupd - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - urpmi - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - vertica_configuration - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - vertica_role - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - vertica_schema - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - vertica_user - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - xbps - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - xml - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). + - zfs - simplify return of boolean values in functions (https://github.com/ansible-collections/community.general/pull/11119). diff --git a/plugins/lookup/merge_variables.py b/plugins/lookup/merge_variables.py index 7be8cbf83c..07f90584af 100644 --- a/plugins/lookup/merge_variables.py +++ b/plugins/lookup/merge_variables.py @@ -163,10 +163,7 @@ class LookupModule(LookupBase): return True group_intersection = [host_group_name for host_group_name in host_groups if host_group_name in self._groups] - if group_intersection: - return True - - return False + return bool(group_intersection) def _var_matches(self, key, search_pattern): if self._pattern_type == "prefix": diff --git a/plugins/module_utils/_mount.py b/plugins/module_utils/_mount.py index 4d2545573f..d3ab3ac4a1 100644 --- a/plugins/module_utils/_mount.py +++ b/plugins/module_utils/_mount.py @@ -47,6 +47,4 @@ def ismount(path): return True # path/.. on a different device as path ino1 = s1.st_ino ino2 = s2.st_ino - if ino1 == ino2: - return True # path/.. is the same i-node as path - return False + return ino1 == ino2 # path/.. is the same i-node as path diff --git a/plugins/module_utils/xenserver.py b/plugins/module_utils/xenserver.py index 954068553e..53b32276d8 100644 --- a/plugins/module_utils/xenserver.py +++ b/plugins/module_utils/xenserver.py @@ -139,10 +139,7 @@ def is_valid_ip_prefix(ip_prefix): ip_prefix_int = int(ip_prefix) - if ip_prefix_int < 0 or ip_prefix_int > 32: - return False - - return True + return not (ip_prefix_int < 0 or ip_prefix_int > 32) def ip_prefix_to_netmask(ip_prefix, skip_check=False): @@ -243,10 +240,7 @@ def is_valid_ip6_prefix(ip6_prefix): ip6_prefix_int = int(ip6_prefix) - if ip6_prefix_int < 0 or ip6_prefix_int > 128: - return False - - return True + return not (ip6_prefix_int < 0 or ip6_prefix_int > 128) def get_object_ref(module, name, uuid=None, obj_type="VM", fail=True, msg_prefix=""): diff --git a/plugins/modules/aerospike_migrations.py b/plugins/modules/aerospike_migrations.py index a32935e24f..fe5cdb4895 100644 --- a/plugins/modules/aerospike_migrations.py +++ b/plugins/modules/aerospike_migrations.py @@ -270,9 +270,7 @@ class Migrations: # if version <4.3 we can't use cluster-stable info cmd # regex hack to check for versions beginning with 0-3 or # beginning with 4.0,4.1,4.2 - if re.search(R"^([0-3]\.|4\.[0-2])", min(self._build_list)): - return False - return True + return not re.search(R"^([0-3]\.|4\.[0-2])", min(self._build_list)) def _update_cluster_namespace_list(self): """make a unique list of namespaces @@ -336,9 +334,7 @@ class Migrations: cluster_keys[cluster_key] = 1 else: cluster_keys[cluster_key] += 1 - if len(cluster_keys.keys()) == 1 and self._start_cluster_key in cluster_keys: - return True - return False + return bool(len(cluster_keys.keys()) == 1 and self._start_cluster_key in cluster_keys) def _cluster_migrates_allowed(self): """ensure all nodes have 'migrate_allowed' in their stats output""" @@ -355,9 +351,7 @@ class Migrations: for node in self._nodes: if self._node_has_migs(node): migs += 1 - if migs == 0: - return False - return True + return migs != 0 def _has_migs(self, local): if local: @@ -376,9 +370,7 @@ class Migrations: if (len(sizes)) > 1: # if we are getting more than 1 size, lets say no return False - if (min(sizes)) >= self.module.params["min_cluster_size"]: - return True - return False + return min(sizes) >= self.module.params["min_cluster_size"] def _cluster_stable(self): """Added 4.3: @@ -403,9 +395,7 @@ class Migrations: if "unstable-cluster" in e.msg: return False raise e - if len(cluster_key) == 1: - return True - return False + return len(cluster_key) == 1 def _cluster_good_state(self): """checks a few things to make sure we're OK to say the cluster diff --git a/plugins/modules/apk.py b/plugins/modules/apk.py index 19fd3c694e..f5008c52ac 100644 --- a/plugins/modules/apk.py +++ b/plugins/modules/apk.py @@ -208,10 +208,7 @@ def query_toplevel(module, name, world): def query_package(module, name): cmd = APK_PATH + ["-v", "info", "--installed", name] rc, stdout, stderr = module.run_command(cmd, check_rc=False) - if rc == 0: - return True - else: - return False + return rc == 0 def query_latest(module, name): @@ -219,18 +216,14 @@ def query_latest(module, name): rc, stdout, stderr = module.run_command(cmd, check_rc=False) search_pattern = rf"({re.escape(name)})-[\d\.\w]+-[\d\w]+\s+(.)\s+[\d\.\w]+-[\d\w]+\s+" match = re.search(search_pattern, stdout) - if match and match.group(2) == "<": - return False - return True + return not (match and match.group(2) == "<") def query_virtual(module, name): cmd = APK_PATH + ["-v", "info", "--description", name] rc, stdout, stderr = module.run_command(cmd, check_rc=False) search_pattern = rf"^{re.escape(name)}: virtual meta package" - if re.search(search_pattern, stdout): - return True - return False + return bool(re.search(search_pattern, stdout)) def get_dependencies(module, name): diff --git a/plugins/modules/apt_rpm.py b/plugins/modules/apt_rpm.py index 3a14370dc5..2b8714859e 100644 --- a/plugins/modules/apt_rpm.py +++ b/plugins/modules/apt_rpm.py @@ -167,10 +167,7 @@ def query_package(module, name): # rpm -q returns 0 if the package is installed, # 1 if it is not installed rc, out, err = module.run_command([RPM_PATH, "-q", name]) - if rc == 0: - return True - else: - return False + return rc == 0 def check_package_version(module, name): @@ -181,9 +178,7 @@ def check_package_version(module, name): rc, out, err = module.run_command([APT_CACHE, "policy", name], environ_update={"LANG": "C"}) installed = re.split("\n |: ", out)[2] candidate = re.split("\n |: ", out)[4] - if installed >= candidate: - return True - return False + return installed >= candidate def query_package_provides(module, name, allow_upgrade=False): diff --git a/plugins/modules/awall.py b/plugins/modules/awall.py index c90e00990c..7c6b26e7e6 100644 --- a/plugins/modules/awall.py +++ b/plugins/modules/awall.py @@ -82,9 +82,7 @@ def activate(module): def is_policy_enabled(module, name): cmd = f"{AWALL_PATH} list" rc, stdout, stderr = module.run_command(cmd) - if re.search(rf"^{name}\s+enabled", stdout, re.MULTILINE): - return True - return False + return bool(re.search(rf"^{name}\s+enabled", stdout, re.MULTILINE)) def enable_policy(module, names, act): diff --git a/plugins/modules/beadm.py b/plugins/modules/beadm.py index 247c744c5e..424d4b4ebd 100644 --- a/plugins/modules/beadm.py +++ b/plugins/modules/beadm.py @@ -194,10 +194,7 @@ class BE: (rc, out, dummy) = self._beadm_list() if rc == 0: - if self._find_be_by_name(out): - return True - else: - return False + return bool(self._find_be_by_name(out)) else: return False diff --git a/plugins/modules/crypttab.py b/plugins/modules/crypttab.py index 0039ffed84..7b8969f70f 100644 --- a/plugins/modules/crypttab.py +++ b/plugins/modules/crypttab.py @@ -237,9 +237,7 @@ class Line: return changed, "updated line" def _line_valid(self, line): - if not line.strip() or line.startswith("#") or len(line.split()) not in (2, 3, 4): - return False - return True + return line.strip() and not line.startswith("#") and len(line.split()) in (2, 3, 4) def _split_line(self, line): fields = line.split() @@ -259,9 +257,7 @@ class Line: return True, "removed line" def valid(self): - if self.name is not None and self.backing_device is not None: - return True - return False + return self.name is not None and self.backing_device is not None def __str__(self): if self.valid(): diff --git a/plugins/modules/gitlab_group_access_token.py b/plugins/modules/gitlab_group_access_token.py index 5a2a669570..21689eb787 100644 --- a/plugins/modules/gitlab_group_access_token.py +++ b/plugins/modules/gitlab_group_access_token.py @@ -228,9 +228,7 @@ class GitLabGroupAccessToken: return False if self.access_token_object.access_level != ACCESS_LEVELS[self._module.params["access_level"]]: return False - if self.access_token_object.expires_at != self._module.params["expires_at"]: - return False - return True + return self.access_token_object.expires_at == self._module.params["expires_at"] def main(): diff --git a/plugins/modules/gitlab_project_access_token.py b/plugins/modules/gitlab_project_access_token.py index 679e260db8..3c037cdb53 100644 --- a/plugins/modules/gitlab_project_access_token.py +++ b/plugins/modules/gitlab_project_access_token.py @@ -224,9 +224,7 @@ class GitLabProjectAccessToken: return False if self.access_token_object.access_level != ACCESS_LEVELS[self._module.params["access_level"]]: return False - if self.access_token_object.expires_at != self._module.params["expires_at"]: - return False - return True + return self.access_token_object.expires_at == self._module.params["expires_at"] def main(): diff --git a/plugins/modules/hg.py b/plugins/modules/hg.py index ed42b1687a..62e3bfe9e2 100644 --- a/plugins/modules/hg.py +++ b/plugins/modules/hg.py @@ -134,10 +134,7 @@ class Hg: def has_local_mods(self): now = self.get_revision() - if "+" in now: - return True - else: - return False + return "+" in now def discard(self): before = self.has_local_mods() @@ -177,10 +174,7 @@ class Hg: discarded = self.discard() if purge: purged = self.purge() - if discarded or purged: - return True - else: - return False + return discarded or purged def pull(self): return self._command(["pull", "-R", self.dest, self.repo]) @@ -207,9 +201,7 @@ class Hg: (rc, out, err) = self._command(["--debug", "id", "-i", "-R", self.dest]) if rc != 0: self.module.fail_json(msg=err) - if out.startswith(self.revision): - return True - return False + return out.startswith(self.revision) # =========================================== diff --git a/plugins/modules/icinga2_host.py b/plugins/modules/icinga2_host.py index 9073341e0b..dfb1d32897 100644 --- a/plugins/modules/icinga2_host.py +++ b/plugins/modules/icinga2_host.py @@ -172,9 +172,7 @@ class icinga2_api: def check_connection(self): ret = self.call_url("v1/status") - if ret["code"] == 200: - return True - return False + return ret["code"] == 200 def exists(self, hostname): data = { diff --git a/plugins/modules/jenkins_job.py b/plugins/modules/jenkins_job.py index 9c8838fab4..8349339f91 100644 --- a/plugins/modules/jenkins_job.py +++ b/plugins/modules/jenkins_job.py @@ -244,9 +244,7 @@ class JenkinsJob: self.result["diff"]["after"] = config_file self.result["diff"]["before"] = machine_file - if machine_file != config_file: - return True - return False + return machine_file != config_file def present_job(self): if self.config is None and self.enabled is None: diff --git a/plugins/modules/logentries.py b/plugins/modules/logentries.py index 853bd59591..6b7fb562a3 100644 --- a/plugins/modules/logentries.py +++ b/plugins/modules/logentries.py @@ -67,10 +67,7 @@ def query_log_status(module, le_path, path, state="present"): if state == "present": rc, out, err = module.run_command([le_path, "followed", path]) - if rc == 0: - return True - - return False + return rc == 0 def follow_log(module, le_path, logs, name=None, logtype=None): diff --git a/plugins/modules/macports.py b/plugins/modules/macports.py index 0294b672b4..f5b84ac28f 100644 --- a/plugins/modules/macports.py +++ b/plugins/modules/macports.py @@ -154,18 +154,12 @@ def query_port(module, port_path, name, state="present"): if state == "present": rc, out, err = module.run_command([port_path, "-q", "installed", name]) - if rc == 0 and out.strip().startswith(f"{name} "): - return True - - return False + return rc == 0 and out.strip().startswith(f"{name} ") elif state == "active": rc, out, err = module.run_command([port_path, "-q", "installed", name]) - if rc == 0 and "(active)" in out: - return True - - return False + return rc == 0 and "(active)" in out def remove_ports(module, port_path, ports, stdout, stderr): diff --git a/plugins/modules/oneandone_firewall_policy.py b/plugins/modules/oneandone_firewall_policy.py index f2b9135559..dca0f7fb4c 100644 --- a/plugins/modules/oneandone_firewall_policy.py +++ b/plugins/modules/oneandone_firewall_policy.py @@ -229,9 +229,7 @@ def _add_server_ips(module, oneandone_conn, firewall_id, server_ids): attach_servers.append(attach_server) if module.check_mode: - if attach_servers: - return True - return False + return bool(attach_servers) firewall_policy = oneandone_conn.attach_server_firewall_policy( firewall_id=firewall_id, server_ips=attach_servers @@ -248,9 +246,7 @@ def _remove_firewall_server(module, oneandone_conn, firewall_id, server_ip_id): try: if module.check_mode: firewall_server = oneandone_conn.get_firewall_server(firewall_id=firewall_id, server_ip_id=server_ip_id) - if firewall_server: - return True - return False + return bool(firewall_server) firewall_policy = oneandone_conn.remove_firewall_server(firewall_id=firewall_id, server_ip_id=server_ip_id) return firewall_policy @@ -273,9 +269,7 @@ def _add_firewall_rules(module, oneandone_conn, firewall_id, rules): if module.check_mode: firewall_policy_id = get_firewall_policy(oneandone_conn, firewall_id) - if firewall_rules and firewall_policy_id: - return True - return False + return bool(firewall_rules and firewall_policy_id) firewall_policy = oneandone_conn.add_firewall_policy_rule( firewall_id=firewall_id, firewall_policy_rules=firewall_rules @@ -292,9 +286,7 @@ def _remove_firewall_rule(module, oneandone_conn, firewall_id, rule_id): try: if module.check_mode: rule = oneandone_conn.get_firewall_policy_rule(firewall_id=firewall_id, rule_id=rule_id) - if rule: - return True - return False + return bool(rule) firewall_policy = oneandone_conn.remove_firewall_rule(firewall_id=firewall_id, rule_id=rule_id) return firewall_policy diff --git a/plugins/modules/oneandone_load_balancer.py b/plugins/modules/oneandone_load_balancer.py index 1619491609..9f24e92a90 100644 --- a/plugins/modules/oneandone_load_balancer.py +++ b/plugins/modules/oneandone_load_balancer.py @@ -282,9 +282,7 @@ def _add_server_ips(module, oneandone_conn, load_balancer_id, server_ids): attach_servers.append(attach_server) if module.check_mode: - if attach_servers: - return True - return False + return bool(attach_servers) load_balancer = oneandone_conn.attach_load_balancer_server( load_balancer_id=load_balancer_id, server_ips=attach_servers @@ -303,9 +301,7 @@ def _remove_load_balancer_server(module, oneandone_conn, load_balancer_id, serve lb_server = oneandone_conn.get_load_balancer_server( load_balancer_id=load_balancer_id, server_ip_id=server_ip_id ) - if lb_server: - return True - return False + return bool(lb_server) load_balancer = oneandone_conn.remove_load_balancer_server( load_balancer_id=load_balancer_id, server_ip_id=server_ip_id @@ -333,9 +329,7 @@ def _add_load_balancer_rules(module, oneandone_conn, load_balancer_id, rules): if module.check_mode: lb_id = get_load_balancer(oneandone_conn, load_balancer_id) - if load_balancer_rules and lb_id: - return True - return False + return bool(load_balancer_rules and lb_id) load_balancer = oneandone_conn.add_load_balancer_rule( load_balancer_id=load_balancer_id, load_balancer_rules=load_balancer_rules @@ -353,9 +347,7 @@ def _remove_load_balancer_rule(module, oneandone_conn, load_balancer_id, rule_id try: if module.check_mode: rule = oneandone_conn.get_load_balancer_rule(load_balancer_id=load_balancer_id, rule_id=rule_id) - if rule: - return True - return False + return bool(rule) load_balancer = oneandone_conn.remove_load_balancer_rule(load_balancer_id=load_balancer_id, rule_id=rule_id) return load_balancer diff --git a/plugins/modules/oneandone_monitoring_policy.py b/plugins/modules/oneandone_monitoring_policy.py index 701b3803a8..7e6345c433 100644 --- a/plugins/modules/oneandone_monitoring_policy.py +++ b/plugins/modules/oneandone_monitoring_policy.py @@ -446,9 +446,7 @@ def _add_ports(module, oneandone_conn, monitoring_policy_id, ports): monitoring_policy_ports.append(monitoring_policy_port) if module.check_mode: - if monitoring_policy_ports: - return True - return False + return bool(monitoring_policy_ports) monitoring_policy = oneandone_conn.add_port( monitoring_policy_id=monitoring_policy_id, ports=monitoring_policy_ports @@ -467,9 +465,7 @@ def _delete_monitoring_policy_port(module, oneandone_conn, monitoring_policy_id, monitoring_policy = oneandone_conn.delete_monitoring_policy_port( monitoring_policy_id=monitoring_policy_id, port_id=port_id ) - if monitoring_policy: - return True - return False + return bool(monitoring_policy) monitoring_policy = oneandone_conn.delete_monitoring_policy_port( monitoring_policy_id=monitoring_policy_id, port_id=port_id @@ -488,9 +484,7 @@ def _modify_port(module, oneandone_conn, monitoring_policy_id, port_id, port): cm_port = oneandone_conn.get_monitoring_policy_port( monitoring_policy_id=monitoring_policy_id, port_id=port_id ) - if cm_port: - return True - return False + return bool(cm_port) monitoring_policy_port = oneandone.client.Port( protocol=port["protocol"], @@ -524,9 +518,7 @@ def _add_processes(module, oneandone_conn, monitoring_policy_id, processes): if module.check_mode: mp_id = get_monitoring_policy(oneandone_conn, monitoring_policy_id) - if monitoring_policy_processes and mp_id: - return True - return False + return bool(monitoring_policy_processes and mp_id) monitoring_policy = oneandone_conn.add_process( monitoring_policy_id=monitoring_policy_id, processes=monitoring_policy_processes @@ -545,9 +537,7 @@ def _delete_monitoring_policy_process(module, oneandone_conn, monitoring_policy_ process = oneandone_conn.get_monitoring_policy_process( monitoring_policy_id=monitoring_policy_id, process_id=process_id ) - if process: - return True - return False + return bool(process) monitoring_policy = oneandone_conn.delete_monitoring_policy_process( monitoring_policy_id=monitoring_policy_id, process_id=process_id @@ -566,9 +556,7 @@ def _modify_process(module, oneandone_conn, monitoring_policy_id, process_id, pr cm_process = oneandone_conn.get_monitoring_policy_process( monitoring_policy_id=monitoring_policy_id, process_id=process_id ) - if cm_process: - return True - return False + return bool(cm_process) monitoring_policy_process = oneandone.client.Process( process=process["process"], alert_if=process["alert_if"], email_notification=process["email_notification"] @@ -595,9 +583,7 @@ def _attach_monitoring_policy_server(module, oneandone_conn, monitoring_policy_i attach_servers.append(attach_server) if module.check_mode: - if attach_servers: - return True - return False + return bool(attach_servers) monitoring_policy = oneandone_conn.attach_monitoring_policy_server( monitoring_policy_id=monitoring_policy_id, servers=attach_servers @@ -616,9 +602,7 @@ def _detach_monitoring_policy_server(module, oneandone_conn, monitoring_policy_i mp_server = oneandone_conn.get_monitoring_policy_server( monitoring_policy_id=monitoring_policy_id, server_id=server_id ) - if mp_server: - return True - return False + return bool(mp_server) monitoring_policy = oneandone_conn.detach_monitoring_policy_server( monitoring_policy_id=monitoring_policy_id, server_id=server_id diff --git a/plugins/modules/oneandone_private_network.py b/plugins/modules/oneandone_private_network.py index 05c9f70d7a..df0bf1e667 100644 --- a/plugins/modules/oneandone_private_network.py +++ b/plugins/modules/oneandone_private_network.py @@ -177,9 +177,7 @@ def _add_servers(module, oneandone_conn, name, members): private_network_id = get_private_network(oneandone_conn, name) if module.check_mode: - if private_network_id and members: - return True - return False + return bool(private_network_id and members) network = oneandone_conn.attach_private_network_servers( private_network_id=private_network_id, server_ids=members diff --git a/plugins/modules/pamd.py b/plugins/modules/pamd.py index 16c88cc9d7..e8cfee5424 100644 --- a/plugins/modules/pamd.py +++ b/plugins/modules/pamd.py @@ -255,9 +255,7 @@ class PamdLine: @property def is_valid(self): - if self.line.strip() == "": - return True - return False + return self.line.strip() == "" def validate(self): if not self.is_valid: @@ -282,9 +280,7 @@ class PamdComment(PamdLine): @property def is_valid(self): - if self.line.startswith("#"): - return True - return False + return self.line.startswith("#") class PamdInclude(PamdLine): @@ -293,9 +289,7 @@ class PamdInclude(PamdLine): @property def is_valid(self): - if self.line.startswith("@include"): - return True - return False + return self.line.startswith("@include") class PamdRule(PamdLine): @@ -399,9 +393,7 @@ class PamdRule(PamdLine): except ValueError: return False - if number >= 0: - return True - return False + return number >= 0 @property def is_valid(self): @@ -484,9 +476,7 @@ class PamdService: return lines def has_rule(self, rule_type, rule_control, rule_path): - if self.get(rule_type, rule_control, rule_path): - return True - return False + return bool(self.get(rule_type, rule_control, rule_path)) def update_rule( self, rule_type, rule_control, rule_path, new_type=None, new_control=None, new_path=None, new_args=None diff --git a/plugins/modules/parted.py b/plugins/modules/parted.py index cbd093cdcb..1d4f8b1080 100644 --- a/plugins/modules/parted.py +++ b/plugins/modules/parted.py @@ -487,10 +487,7 @@ def check_parted_label(device): # Older parted versions return a message in the stdout and RC > 0. rc, out, err = module.run_command([parted_exec, "-s", "-m", device, "print"]) - if rc != 0 and "unrecognised disk label" in out.lower(): - return True - - return False + return rc != 0 and "unrecognised disk label" in out.lower() def parse_parted_version(out): diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index f0f2c4ec74..f4fc888577 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -358,10 +358,7 @@ class Rhsm: args = [SUBMAN_CMD, "identity"] rc, stdout, stderr = self.module.run_command(args, check_rc=False) - if rc == 0: - return True - else: - return False + return rc == 0 def _has_dbus_interface(self): """ @@ -607,7 +604,7 @@ class Rhsm: if distro_id == "fedora" and distro_version[0] >= 41: return True # Assume EL distros here. - if distro_version[0] >= 10: + if distro_version[0] >= 10: # noqa: SIM103 return True return False @@ -628,7 +625,7 @@ class Rhsm: # if the 2nd part of the version is empty, it means it is # CentOS Stream, and thus we can assume it has the latest # version of subscription-manager. - if distro_id == "centos" and ( + if distro_id == "centos" and ( # noqa: SIM103 (distro_version[0] == 8 and (distro_version[1] >= 6 or distro_version_parts[1] == "")) or distro_version[0] >= 9 ): @@ -662,7 +659,7 @@ class Rhsm: # CentOS: since the change was only done in EL 9, then there is # only CentOS Stream for 9, and thus we can assume it has the # latest version of subscription-manager. - if distro_id == "centos" and distro_version[0] >= 9: + if distro_id == "centos" and distro_version[0] >= 9: # noqa: SIM103 return True # Unknown or old distro: assume it does not support # the new option. @@ -695,7 +692,7 @@ class Rhsm: # if the 2nd part of the version is empty, it means it is # CentOS Stream, and thus we can assume it has the latest # version of subscription-manager. - if distro_id == "centos" and ( + if distro_id == "centos" and ( # noqa: SIM103 (distro_version[0] == 8 and (distro_version[1] >= 6 or distro_version_parts[1] == "")) or distro_version[0] >= 9 ): @@ -909,10 +906,7 @@ class RhsmPool: def subscribe(self): args = f"subscription-manager attach --pool {self.get_pool_id()}" rc, stdout, stderr = self.module.run_command(args, check_rc=True) - if rc == 0: - return True - else: - return False + return rc == 0 class RhsmPools: diff --git a/plugins/modules/riak.py b/plugins/modules/riak.py index 173e2e14f8..fec69bd2da 100644 --- a/plugins/modules/riak.py +++ b/plugins/modules/riak.py @@ -91,10 +91,7 @@ from ansible.module_utils.urls import fetch_url def ring_check(module, riak_admin_bin): cmd = riak_admin_bin + ["ringready"] rc, out, err = module.run_command(cmd) - if rc == 0 and "TRUE All nodes agree on the ring" in out: - return True - else: - return False + return rc == 0 and "TRUE All nodes agree on the ring" in out def main(): diff --git a/plugins/modules/slack.py b/plugins/modules/slack.py index f417fb99ef..cddb9b4890 100644 --- a/plugins/modules/slack.py +++ b/plugins/modules/slack.py @@ -284,9 +284,7 @@ escape_table = { def is_valid_hex_color(color_choice): - if re.match(r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", color_choice): - return True - return False + return bool(re.match(r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", color_choice)) def escape_quotes(text): diff --git a/plugins/modules/slackpkg.py b/plugins/modules/slackpkg.py index 5dbed482ff..6dc422beaa 100644 --- a/plugins/modules/slackpkg.py +++ b/plugins/modules/slackpkg.py @@ -83,10 +83,7 @@ def query_package(module, slackpkg_path, name): pattern = re.compile(f"^{re.escape(name)}-[^-]+-({re.escape(machine)}|noarch|fw)-[^-]+$") packages = [f for f in os.listdir("/var/log/packages") if pattern.match(f)] - if len(packages) > 0: - return True - - return False + return bool(packages) def remove_packages(module, slackpkg_path, packages): diff --git a/plugins/modules/solaris_zone.py b/plugins/modules/solaris_zone.py index beaa5635c2..78e1661e3e 100644 --- a/plugins/modules/solaris_zone.py +++ b/plugins/modules/solaris_zone.py @@ -364,10 +364,7 @@ class Zone: def exists(self): cmd = [self.zoneadm_cmd, "-z", self.name, "list"] (rc, out, err) = self.module.run_command(cmd) - if rc == 0: - return True - else: - return False + return rc == 0 def is_running(self): return self.status() == "running" diff --git a/plugins/modules/svr4pkg.py b/plugins/modules/svr4pkg.py index 9f1eb163fa..a291884df0 100644 --- a/plugins/modules/svr4pkg.py +++ b/plugins/modules/svr4pkg.py @@ -116,10 +116,7 @@ def package_installed(module, name, category): cmd.append("-c") cmd.append(name) rc, out, err = module.run_command(cmd) - if rc == 0: - return True - else: - return False + return rc == 0 def create_admin_file(): diff --git a/plugins/modules/swupd.py b/plugins/modules/swupd.py index 6915595097..84b192ec1e 100644 --- a/plugins/modules/swupd.py +++ b/plugins/modules/swupd.py @@ -173,10 +173,7 @@ class Swupd: self.failed = True self.msg = "Failed to check for filesystem inconsistencies." - if self.FILES_NOT_MATCH in self.stdout: - return True - - return False + return self.FILES_NOT_MATCH in self.stdout def install_bundle(self, bundle): """Installs a bundle with `swupd bundle-add bundle`""" diff --git a/plugins/modules/urpmi.py b/plugins/modules/urpmi.py index 915eaa190b..915b732813 100644 --- a/plugins/modules/urpmi.py +++ b/plugins/modules/urpmi.py @@ -93,10 +93,7 @@ def query_package(module, name, root): rpm_path = module.get_bin_path("rpm", True) cmd = [rpm_path, "-q", name] + root_option(root) rc, stdout, stderr = module.run_command(cmd, check_rc=False) - if rc == 0: - return True - else: - return False + return rc == 0 def query_package_provides(module, name, root): diff --git a/plugins/modules/vertica_configuration.py b/plugins/modules/vertica_configuration.py index f3a5e23585..86f630b47a 100644 --- a/plugins/modules/vertica_configuration.py +++ b/plugins/modules/vertica_configuration.py @@ -119,9 +119,7 @@ def get_configuration_facts(cursor, parameter_name=""): def check(configuration_facts, parameter_name, current_value): parameter_key = parameter_name.lower() - if current_value and current_value.lower() != configuration_facts[parameter_key]["current_value"].lower(): - return False - return True + return not (current_value and current_value.lower() != configuration_facts[parameter_key]["current_value"].lower()) def present(configuration_facts, cursor, parameter_name, current_value): diff --git a/plugins/modules/vertica_role.py b/plugins/modules/vertica_role.py index 70c1bef45b..03e8df0b46 100644 --- a/plugins/modules/vertica_role.py +++ b/plugins/modules/vertica_role.py @@ -137,9 +137,7 @@ def check(role_facts, role, assigned_roles): role_key = role.lower() if role_key not in role_facts: return False - if assigned_roles and sorted(assigned_roles) != sorted(role_facts[role_key]["assigned_roles"]): - return False - return True + return not (assigned_roles and sorted(assigned_roles) != sorted(role_facts[role_key]["assigned_roles"])) def present(role_facts, cursor, role, assigned_roles): diff --git a/plugins/modules/vertica_schema.py b/plugins/modules/vertica_schema.py index d26740ecf6..071b3f764f 100644 --- a/plugins/modules/vertica_schema.py +++ b/plugins/modules/vertica_schema.py @@ -189,9 +189,7 @@ def check(schema_facts, schema, usage_roles, create_roles, owner): return False if sorted(usage_roles) != sorted(schema_facts[schema_key]["usage_roles"]): return False - if sorted(create_roles) != sorted(schema_facts[schema_key]["create_roles"]): - return False - return True + return sorted(create_roles) == sorted(schema_facts[schema_key]["create_roles"]) def present(schema_facts, cursor, schema, usage_roles, create_roles, owner): diff --git a/plugins/modules/vertica_user.py b/plugins/modules/vertica_user.py index 6575fed8a0..9d4be97aeb 100644 --- a/plugins/modules/vertica_user.py +++ b/plugins/modules/vertica_user.py @@ -197,12 +197,13 @@ def check(user_facts, user, profile, resource_pool, locked, password, expired, l and ldap != (user_facts[user_key]["expired"] == "True") ): return False - if roles and ( - sorted(roles) != sorted(user_facts[user_key]["roles"]) - or sorted(roles) != sorted(user_facts[user_key]["default_roles"]) - ): - return False - return True + return not ( + roles + and ( + sorted(roles) != sorted(user_facts[user_key]["roles"]) + or sorted(roles) != sorted(user_facts[user_key]["default_roles"]) + ) + ) def present(user_facts, cursor, user, profile, resource_pool, locked, password, expired, ldap, roles): diff --git a/plugins/modules/xbps.py b/plugins/modules/xbps.py index ab76bbf326..fca8995c62 100644 --- a/plugins/modules/xbps.py +++ b/plugins/modules/xbps.py @@ -216,10 +216,7 @@ def update_package_db(module, xbps_path): module.fail_json(msg="Failed to import pubkey for repository") if rc != 0: module.fail_json(msg="Could not update package db") - if "avg rate" in stdout: - return True - else: - return False + return "avg rate" in stdout def upgrade_xbps(module, xbps_path, exit_on_success=False): diff --git a/plugins/modules/xml.py b/plugins/modules/xml.py index 703358fefb..40686c6f25 100644 --- a/plugins/modules/xml.py +++ b/plugins/modules/xml.py @@ -448,9 +448,7 @@ def is_attribute(tree, xpath, namespaces): def xpath_matches(tree, xpath, namespaces): """Test if a node exists""" - if tree.xpath(xpath, namespaces=namespaces): - return True - return False + return bool(tree.xpath(xpath, namespaces=namespaces)) def delete_xpath_target(module, tree, xpath, namespaces): diff --git a/plugins/modules/zfs.py b/plugins/modules/zfs.py index 8c9cef8497..492fa62d27 100644 --- a/plugins/modules/zfs.py +++ b/plugins/modules/zfs.py @@ -115,9 +115,7 @@ class Zfs: version = out.splitlines()[-1].split()[2] if version == "-": return True - if int(version) == 5000: - return True - return False + return int(version) == 5000 def check_enhanced_sharing(self): if self.is_solaris and not self.is_openzfs: diff --git a/ruff.toml b/ruff.toml index 693108f57c..f32ea6ff04 100644 --- a/ruff.toml +++ b/ruff.toml @@ -32,7 +32,6 @@ ignore = [ "B026", # star-arg-unpacking-after-keyword-arg "B904", # raise-without-from-inside-except "SIM102", # collapsible-if - "SIM103", # needless-bool "SIM110", # reimplemented-builtin "SIM112", # uncapitalized-environment-variables "SIM114", # if-with-same-arms