mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
fix ruff case SIM103 (#11119)
* fix ruff case SIM103 * add changelog frag
This commit is contained in:
parent
58bb1e7c04
commit
41923e43bd
39 changed files with 115 additions and 230 deletions
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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=""):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
# ===========================================
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -179,10 +179,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`"""
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue