mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Run black -l 120 on all files, again (#943)
Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
parent
aa20ede71e
commit
f2e813671a
32 changed files with 221 additions and 762 deletions
|
|
@ -46,20 +46,14 @@ ARGUMENTS_OPTS_DICT = {
|
|||
}
|
||||
|
||||
|
||||
def run_podman_command(
|
||||
module, executable="podman", args=None, expected_rc=0, ignore_errors=False
|
||||
):
|
||||
def run_podman_command(module, executable="podman", args=None, expected_rc=0, ignore_errors=False):
|
||||
if not isinstance(executable, list):
|
||||
command = [executable]
|
||||
if args is not None:
|
||||
command.extend(args)
|
||||
rc, out, err = module.run_command(command)
|
||||
if not ignore_errors and rc != expected_rc:
|
||||
module.fail_json(
|
||||
msg="Failed to run {command} {args}: {err}".format(
|
||||
command=command, args=args, err=err
|
||||
)
|
||||
)
|
||||
module.fail_json(msg="Failed to run {command} {args}: {err}".format(command=command, args=args, err=err))
|
||||
return rc, out, err
|
||||
|
||||
|
||||
|
|
@ -96,11 +90,7 @@ def run_generate_systemd_command(module, module_params, name, version):
|
|||
if (sysconf.get("stop_timeout") is not None) or (sysconf.get("time") is not None):
|
||||
# Select correct parameter name based on version
|
||||
arg_name = "stop-timeout" if gt4ver else "time"
|
||||
arg_value = (
|
||||
sysconf.get("stop_timeout")
|
||||
if sysconf.get("stop_timeout") is not None
|
||||
else sysconf.get("time")
|
||||
)
|
||||
arg_value = sysconf.get("stop_timeout") if sysconf.get("stop_timeout") is not None else sysconf.get("time")
|
||||
command.extend(["--%s=%s" % (arg_name, arg_value)])
|
||||
if sysconf.get("start_timeout") is not None:
|
||||
command.extend(["--start-timeout=%s" % sysconf["start_timeout"]])
|
||||
|
|
@ -158,9 +148,7 @@ def compare_systemd_file_content(file_path, file_content):
|
|||
|
||||
# Function to remove comments from file content
|
||||
def remove_comments(content):
|
||||
return "\n".join(
|
||||
[line for line in content.splitlines() if not line.startswith("#")]
|
||||
)
|
||||
return "\n".join([line for line in content.splitlines() if not line.startswith("#")])
|
||||
|
||||
# Remove comments from both file contents before comparison
|
||||
current_unit_file_content_nocmnt = remove_comments(current_unit_file_content)
|
||||
|
|
@ -170,14 +158,10 @@ def compare_systemd_file_content(file_path, file_content):
|
|||
|
||||
# Get the different lines between the two contents
|
||||
diff_in_file = [
|
||||
line
|
||||
for line in unit_content_nocmnt.splitlines()
|
||||
if line not in current_unit_file_content_nocmnt.splitlines()
|
||||
line for line in unit_content_nocmnt.splitlines() if line not in current_unit_file_content_nocmnt.splitlines()
|
||||
]
|
||||
diff_in_string = [
|
||||
line
|
||||
for line in current_unit_file_content_nocmnt.splitlines()
|
||||
if line not in unit_content_nocmnt.splitlines()
|
||||
line for line in current_unit_file_content_nocmnt.splitlines() if line not in unit_content_nocmnt.splitlines()
|
||||
]
|
||||
|
||||
return diff_in_string, diff_in_file
|
||||
|
|
@ -190,9 +174,7 @@ def generate_systemd(module, module_params, name, version):
|
|||
"diff": {},
|
||||
}
|
||||
sysconf = module_params["generate_systemd"]
|
||||
rc, systemd, err = run_generate_systemd_command(
|
||||
module, module_params, name, version
|
||||
)
|
||||
rc, systemd, err = run_generate_systemd_command(module, module_params, name, version)
|
||||
if rc != 0:
|
||||
module.log("PODMAN-CONTAINER-DEBUG: Error generating systemd: %s" % err)
|
||||
if sysconf:
|
||||
|
|
@ -209,8 +191,7 @@ def generate_systemd(module, module_params, name, version):
|
|||
result["changed"] = True
|
||||
if not os.path.isdir(full_path):
|
||||
module.fail_json(
|
||||
"Path %s is not a directory! "
|
||||
"Can not save systemd unit files there!" % full_path
|
||||
"Path %s is not a directory! " "Can not save systemd unit files there!" % full_path
|
||||
)
|
||||
for file_name, file_content in data.items():
|
||||
file_name += ".service"
|
||||
|
|
@ -218,42 +199,22 @@ def generate_systemd(module, module_params, name, version):
|
|||
result["changed"] = True
|
||||
if result["diff"].get("before") is None:
|
||||
result["diff"] = {"before": {}, "after": {}}
|
||||
result["diff"]["before"].update(
|
||||
{
|
||||
"systemd_{file_name}.service".format(
|
||||
file_name=file_name
|
||||
): ""
|
||||
}
|
||||
)
|
||||
result["diff"]["before"].update({"systemd_{file_name}.service".format(file_name=file_name): ""})
|
||||
result["diff"]["after"].update(
|
||||
{
|
||||
"systemd_{file_name}.service".format(
|
||||
file_name=file_name
|
||||
): file_content
|
||||
}
|
||||
{"systemd_{file_name}.service".format(file_name=file_name): file_content}
|
||||
)
|
||||
|
||||
else:
|
||||
diff_ = compare_systemd_file_content(
|
||||
os.path.join(full_path, file_name), file_content
|
||||
)
|
||||
diff_ = compare_systemd_file_content(os.path.join(full_path, file_name), file_content)
|
||||
if diff_:
|
||||
result["changed"] = True
|
||||
if result["diff"].get("before") is None:
|
||||
result["diff"] = {"before": {}, "after": {}}
|
||||
result["diff"]["before"].update(
|
||||
{
|
||||
"systemd_{file_name}.service".format(
|
||||
file_name=file_name
|
||||
): "\n".join(diff_[0])
|
||||
}
|
||||
{"systemd_{file_name}.service".format(file_name=file_name): "\n".join(diff_[0])}
|
||||
)
|
||||
result["diff"]["after"].update(
|
||||
{
|
||||
"systemd_{file_name}.service".format(
|
||||
file_name=file_name
|
||||
): "\n".join(diff_[1])
|
||||
}
|
||||
{"systemd_{file_name}.service".format(file_name=file_name): "\n".join(diff_[1])}
|
||||
)
|
||||
with open(os.path.join(full_path, file_name), "w") as f:
|
||||
f.write(file_content)
|
||||
|
|
@ -290,9 +251,7 @@ def delete_systemd(module, module_params, name, version):
|
|||
# We don't know where systemd files are located, nothing to delete
|
||||
module.log("PODMAN-CONTAINER-DEBUG: Not deleting systemd file - no path!")
|
||||
return
|
||||
rc, systemd, err = run_generate_systemd_command(
|
||||
module, module_params, name, version
|
||||
)
|
||||
rc, systemd, err = run_generate_systemd_command(module, module_params, name, version)
|
||||
if rc != 0:
|
||||
module.log("PODMAN-CONTAINER-DEBUG: Error generating systemd: %s" % err)
|
||||
return
|
||||
|
|
@ -390,15 +349,11 @@ def normalize_signal(signal_name_or_number):
|
|||
|
||||
|
||||
def get_podman_version(module, fail=True):
|
||||
executable = (
|
||||
module.params["executable"] if module.params["executable"] else "podman"
|
||||
)
|
||||
executable = module.params["executable"] if module.params["executable"] else "podman"
|
||||
rc, out, err = module.run_command([executable, b"--version"])
|
||||
if rc != 0 or not out or "version" not in out:
|
||||
if fail:
|
||||
module.fail_json(
|
||||
msg="'%s --version' run failed! Error: %s" % (executable, err)
|
||||
)
|
||||
module.fail_json(msg="'%s --version' run failed! Error: %s" % (executable, err))
|
||||
return None
|
||||
return out.split("version")[1].strip()
|
||||
|
||||
|
|
@ -477,15 +432,7 @@ def diff_generic(params, info_config, module_arg, cmd_arg, boolean_type=False):
|
|||
elif isinstance(after, dict):
|
||||
if module_arg == "log_opt" and "max_size" in after:
|
||||
after["max-size"] = after.pop("max_size")
|
||||
after = ",".join(
|
||||
sorted(
|
||||
[
|
||||
str(k).lower() + "=" + str(v).lower()
|
||||
for k, v in after.items()
|
||||
if v is not None
|
||||
]
|
||||
)
|
||||
)
|
||||
after = ",".join(sorted([str(k).lower() + "=" + str(v).lower() for k, v in after.items() if v is not None]))
|
||||
if before:
|
||||
before = ",".join(sorted([j.lower() for j in before]))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -128,15 +128,11 @@ ARGUMENTS_SPEC_CONTAINER = dict(
|
|||
label=dict(type="dict", aliases=["labels"]),
|
||||
label_file=dict(type="str"),
|
||||
log_driver=dict(type="str", choices=["k8s-file", "journald", "json-file"]),
|
||||
log_level=dict(
|
||||
type="str", choices=["debug", "info", "warn", "error", "fatal", "panic"]
|
||||
),
|
||||
log_level=dict(type="str", choices=["debug", "info", "warn", "error", "fatal", "panic"]),
|
||||
log_opt=dict(
|
||||
type="dict",
|
||||
aliases=["log_options"],
|
||||
options=dict(
|
||||
max_size=dict(type="str"), path=dict(type="str"), tag=dict(type="str")
|
||||
),
|
||||
options=dict(max_size=dict(type="str"), path=dict(type="str"), tag=dict(type="str")),
|
||||
),
|
||||
mac_address=dict(type="str"),
|
||||
memory=dict(type="str"),
|
||||
|
|
@ -163,9 +159,7 @@ ARGUMENTS_SPEC_CONTAINER = dict(
|
|||
preserve_fd=dict(type="list", elements="str"),
|
||||
preserve_fds=dict(type="str"),
|
||||
privileged=dict(type="bool"),
|
||||
publish=dict(
|
||||
type="list", elements="str", aliases=["ports", "published", "published_ports"]
|
||||
),
|
||||
publish=dict(type="list", elements="str", aliases=["ports", "published", "published_ports"]),
|
||||
publish_all=dict(type="bool"),
|
||||
pull=dict(type="str", choices=["always", "missing", "never", "newer"]),
|
||||
quadlet_dir=dict(type="path"),
|
||||
|
|
@ -244,17 +238,11 @@ def update_options(opts_dict, container):
|
|||
container[key] = container.pop(k)
|
||||
else:
|
||||
key = k
|
||||
if ARGUMENTS_SPEC_CONTAINER[key]["type"] == "list" and not isinstance(
|
||||
container[key], list
|
||||
):
|
||||
if ARGUMENTS_SPEC_CONTAINER[key]["type"] == "list" and not isinstance(container[key], list):
|
||||
opts_dict[key] = [container[key]]
|
||||
elif ARGUMENTS_SPEC_CONTAINER[key]["type"] == "bool" and not isinstance(
|
||||
container[key], bool
|
||||
):
|
||||
elif ARGUMENTS_SPEC_CONTAINER[key]["type"] == "bool" and not isinstance(container[key], bool):
|
||||
opts_dict[key] = to_bool(container[key])
|
||||
elif ARGUMENTS_SPEC_CONTAINER[key]["type"] == "int" and not isinstance(
|
||||
container[key], int
|
||||
):
|
||||
elif ARGUMENTS_SPEC_CONTAINER[key]["type"] == "int" and not isinstance(container[key], int):
|
||||
opts_dict[key] = int(container[key])
|
||||
else:
|
||||
opts_dict[key] = container[key]
|
||||
|
|
@ -295,9 +283,7 @@ class PodmanModuleParams:
|
|||
if self.action in ["create", "run"]:
|
||||
cmd = [self.action, "--name", self.params["name"]]
|
||||
all_param_methods = [
|
||||
func
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func)) and func.startswith("addparam")
|
||||
func for func in dir(self) if callable(getattr(self, func)) and func.startswith("addparam")
|
||||
]
|
||||
params_set = (i for i in self.params if self.params[i] is not None)
|
||||
for param in params_set:
|
||||
|
|
@ -317,11 +303,7 @@ class PodmanModuleParams:
|
|||
def complete_params(cmd):
|
||||
if self.params["attach"] and self.action == "start":
|
||||
cmd.append("--attach")
|
||||
if (
|
||||
self.params["detach"] is False
|
||||
and self.action == "start"
|
||||
and "--attach" not in cmd
|
||||
):
|
||||
if self.params["detach"] is False and self.action == "start" and "--attach" not in cmd:
|
||||
cmd.append("--attach")
|
||||
if self.params["detach_keys"] and self.action == "start":
|
||||
cmd += ["--detach-keys", self.params["detach_keys"]]
|
||||
|
|
@ -353,14 +335,12 @@ class PodmanModuleParams:
|
|||
if minv and LooseVersion(minv) > LooseVersion(self.podman_version):
|
||||
self.module.fail_json(
|
||||
msg="Parameter %s is supported from podman "
|
||||
"version %s only! Current version is %s"
|
||||
% (param, minv, self.podman_version)
|
||||
"version %s only! Current version is %s" % (param, minv, self.podman_version)
|
||||
)
|
||||
if maxv and LooseVersion(maxv) < LooseVersion(self.podman_version):
|
||||
self.module.fail_json(
|
||||
msg="Parameter %s is supported till podman "
|
||||
"version %s only! Current version is %s"
|
||||
% (param, minv, self.podman_version)
|
||||
"version %s only! Current version is %s" % (param, minv, self.podman_version)
|
||||
)
|
||||
|
||||
def addparam_annotation(self, c):
|
||||
|
|
@ -504,9 +484,7 @@ class PodmanModuleParams:
|
|||
for env_value in self.params["env"].items():
|
||||
c += [
|
||||
"--env",
|
||||
b"=".join(
|
||||
[to_bytes(k, errors="surrogate_or_strict") for k in env_value]
|
||||
),
|
||||
b"=".join([to_bytes(k, errors="surrogate_or_strict") for k in env_value]),
|
||||
]
|
||||
return c
|
||||
|
||||
|
|
@ -529,9 +507,7 @@ class PodmanModuleParams:
|
|||
for env_merge in self.params["env_merge"].items():
|
||||
c += [
|
||||
"--env-merge",
|
||||
b"=".join(
|
||||
[to_bytes(k, errors="surrogate_or_strict") for k in env_merge]
|
||||
),
|
||||
b"=".join([to_bytes(k, errors="surrogate_or_strict") for k in env_merge]),
|
||||
]
|
||||
return c
|
||||
|
||||
|
|
@ -941,9 +917,7 @@ class PodmanDefaults:
|
|||
def default_dict(self):
|
||||
# make here any changes to self.defaults related to podman version
|
||||
# https://github.com/containers/libpod/pull/5669
|
||||
if LooseVersion(self.version) >= LooseVersion("1.8.0") and LooseVersion(
|
||||
self.version
|
||||
) < LooseVersion("1.9.0"):
|
||||
if LooseVersion(self.version) >= LooseVersion("1.8.0") and LooseVersion(self.version) < LooseVersion("1.9.0"):
|
||||
self.defaults["cpu_shares"] = 1024
|
||||
if LooseVersion(self.version) >= LooseVersion("3.0.0"):
|
||||
self.defaults["log_level"] = "warning"
|
||||
|
|
@ -994,9 +968,7 @@ class PodmanContainerDiff:
|
|||
|
||||
"""
|
||||
info_config = self.info["config"]
|
||||
before, after = diff_generic(
|
||||
self.params, info_config, module_arg, cmd_arg, boolean_type
|
||||
)
|
||||
before, after = diff_generic(self.params, info_config, module_arg, cmd_arg, boolean_type)
|
||||
return self._diff_update_and_compare(module_arg, before, after)
|
||||
|
||||
def diffparam_annotation(self):
|
||||
|
|
@ -1174,9 +1146,7 @@ class PodmanContainerDiff:
|
|||
|
||||
def diffparam_etc_hosts(self):
|
||||
if self.info["hostconfig"]["extrahosts"]:
|
||||
before = dict(
|
||||
[i.split(":", 1) for i in self.info["hostconfig"]["extrahosts"]]
|
||||
)
|
||||
before = dict([i.split(":", 1) for i in self.info["hostconfig"]["extrahosts"]])
|
||||
else:
|
||||
before = {}
|
||||
after = self.params["etc_hosts"] or {}
|
||||
|
|
@ -1215,9 +1185,7 @@ class PodmanContainerDiff:
|
|||
else:
|
||||
before = ""
|
||||
after = self.params["healthcheck_failure_action"] or before
|
||||
return self._diff_update_and_compare(
|
||||
"healthcheckonfailureaction", before, after
|
||||
)
|
||||
return self._diff_update_and_compare("healthcheckonfailureaction", before, after)
|
||||
|
||||
def diffparam_healthcheck_interval(self):
|
||||
return self._diff_generic("healthcheck_interval", "--healthcheck-interval")
|
||||
|
|
@ -1226,17 +1194,13 @@ class PodmanContainerDiff:
|
|||
return self._diff_generic("healthcheck_retries", "--healthcheck-retries")
|
||||
|
||||
def diffparam_healthcheck_start_period(self):
|
||||
return self._diff_generic(
|
||||
"healthcheck_start_period", "--healthcheck-start-period"
|
||||
)
|
||||
return self._diff_generic("healthcheck_start_period", "--healthcheck-start-period")
|
||||
|
||||
def diffparam_health_startup_cmd(self):
|
||||
return self._diff_generic("health_startup_cmd", "--health-startup-cmd")
|
||||
|
||||
def diffparam_health_startup_interval(self):
|
||||
return self._diff_generic(
|
||||
"health_startup_interval", "--health-startup-interval"
|
||||
)
|
||||
return self._diff_generic("health_startup_interval", "--health-startup-interval")
|
||||
|
||||
def diffparam_health_startup_retries(self):
|
||||
return self._diff_generic("health_startup_retries", "--health-startup-retries")
|
||||
|
|
@ -1309,9 +1273,7 @@ class PodmanContainerDiff:
|
|||
before = self.info["config"]["labels"] or {}
|
||||
after = self.image_info.get("labels") or {}
|
||||
if self.params["label"]:
|
||||
after.update(
|
||||
{str(k).lower(): str(v) for k, v in self.params["label"].items()}
|
||||
)
|
||||
after.update({str(k).lower(): str(v) for k, v in self.params["label"].items()})
|
||||
# Strip out labels that are coming from systemd files
|
||||
# https://github.com/containers/ansible-podman-collections/issues/276
|
||||
if "podman_systemd_unit" in before:
|
||||
|
|
@ -1353,9 +1315,7 @@ class PodmanContainerDiff:
|
|||
return self._diff_generic("network_aliases", "--network-alias")
|
||||
|
||||
def diffparam_no_healthcheck(self):
|
||||
return self._diff_generic(
|
||||
"no_healthcheck", "--no-healthcheck", boolean_type=True
|
||||
)
|
||||
return self._diff_generic("no_healthcheck", "--no-healthcheck", boolean_type=True)
|
||||
|
||||
def diffparam_no_hosts(self):
|
||||
return self._diff_generic("no_hosts", "--no-hosts")
|
||||
|
|
@ -1505,15 +1465,7 @@ class PodmanContainerDiff:
|
|||
if before is None and after is None:
|
||||
return self._diff_update_and_compare("tmpfs", before, after)
|
||||
if after is not None:
|
||||
after = ",".join(
|
||||
sorted(
|
||||
[
|
||||
str(k).lower() + ":" + str(v).lower()
|
||||
for k, v in after.items()
|
||||
if v is not None
|
||||
]
|
||||
)
|
||||
)
|
||||
after = ",".join(sorted([str(k).lower() + ":" + str(v).lower() for k, v in after.items() if v is not None]))
|
||||
if before:
|
||||
before = ",".join(sorted([j.lower() for j in before]))
|
||||
else:
|
||||
|
|
@ -1559,14 +1511,9 @@ class PodmanContainerDiff:
|
|||
before = None
|
||||
after = self.params["volume"]
|
||||
if after is not None:
|
||||
after = [
|
||||
":".join([clean_volume(i) for i in v.split(":")[:3]])
|
||||
for v in self.params["volume"]
|
||||
]
|
||||
after = [":".join([clean_volume(i) for i in v.split(":")[:3]]) for v in self.params["volume"]]
|
||||
if before is not None:
|
||||
before = [
|
||||
":".join([clean_volume(i) for i in v.split(":")[:3]]) for v in before
|
||||
]
|
||||
before = [":".join([clean_volume(i) for i in v.split(":")[:3]]) for v in before]
|
||||
if before is None and after is None:
|
||||
return self._diff_update_and_compare("volume", before, after)
|
||||
if after is not None:
|
||||
|
|
@ -1582,11 +1529,7 @@ class PodmanContainerDiff:
|
|||
return self._diff_generic("workdir", "--workdir")
|
||||
|
||||
def is_different(self):
|
||||
diff_func_list = [
|
||||
func
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func)) and func.startswith("diffparam")
|
||||
]
|
||||
diff_func_list = [func for func in dir(self) if callable(getattr(self, func)) and func.startswith("diffparam")]
|
||||
fail_fast = not bool(self.module._diff)
|
||||
different = False
|
||||
for func_name in diff_func_list:
|
||||
|
|
@ -1695,18 +1638,8 @@ class PodmanContainer:
|
|||
is_different = diffcheck.is_different()
|
||||
diffs = diffcheck.diff
|
||||
if self.module._diff and is_different and diffs["before"] and diffs["after"]:
|
||||
self.diff["before"] = (
|
||||
"\n".join(
|
||||
["%s - %s" % (k, v) for k, v in sorted(diffs["before"].items())]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
self.diff["after"] = (
|
||||
"\n".join(
|
||||
["%s - %s" % (k, v) for k, v in sorted(diffs["after"].items())]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
self.diff["before"] = "\n".join(["%s - %s" % (k, v) for k, v in sorted(diffs["before"].items())]) + "\n"
|
||||
self.diff["after"] = "\n".join(["%s - %s" % (k, v) for k, v in sorted(diffs["after"].items())]) + "\n"
|
||||
return is_different
|
||||
|
||||
@property
|
||||
|
|
@ -1722,9 +1655,7 @@ class PodmanContainer:
|
|||
def get_info(self):
|
||||
"""Inspect container and gather info about it."""
|
||||
# pylint: disable=unused-variable
|
||||
rc, out, err = self.module.run_command(
|
||||
[self.module_params["executable"], b"container", b"inspect", self.name]
|
||||
)
|
||||
rc, out, err = self.module.run_command([self.module_params["executable"], b"container", b"inspect", self.name])
|
||||
return json.loads(out)[0] if rc == 0 else {}
|
||||
|
||||
def get_image_info(self):
|
||||
|
|
@ -1741,20 +1672,14 @@ class PodmanContainer:
|
|||
self.module_params["image"].replace("docker://", ""),
|
||||
]
|
||||
)
|
||||
self.module.log(
|
||||
"PODMAN-CONTAINER-DEBUG: %s: %s" % (out, self.module_params["image"])
|
||||
)
|
||||
self.module.log("PODMAN-CONTAINER-DEBUG: %s: %s" % (out, self.module_params["image"]))
|
||||
return json.loads(out)[0] if rc == 0 else {}
|
||||
|
||||
def _get_podman_version(self):
|
||||
# pylint: disable=unused-variable
|
||||
rc, out, err = self.module.run_command(
|
||||
[self.module_params["executable"], b"--version"]
|
||||
)
|
||||
rc, out, err = self.module.run_command([self.module_params["executable"], b"--version"])
|
||||
if rc != 0 or not out or "version" not in out:
|
||||
self.module.fail_json(
|
||||
msg="%s run failed!" % self.module_params["executable"]
|
||||
)
|
||||
self.module.fail_json(msg="%s run failed!" % self.module_params["executable"])
|
||||
return out.split("version")[1].strip()
|
||||
|
||||
def _perform_action(self, action):
|
||||
|
|
@ -1770,9 +1695,7 @@ class PodmanContainer:
|
|||
self.version,
|
||||
self.module,
|
||||
).construct_command_from_params()
|
||||
full_cmd = " ".join(
|
||||
[self.module_params["executable"]] + [to_native(i) for i in b_command]
|
||||
)
|
||||
full_cmd = " ".join([self.module_params["executable"]] + [to_native(i) for i in b_command])
|
||||
self.actions.append(full_cmd)
|
||||
if self.module.check_mode:
|
||||
self.module.log("PODMAN-CONTAINER-DEBUG (check_mode): %s" % full_cmd)
|
||||
|
|
@ -1790,8 +1713,7 @@ class PodmanContainer:
|
|||
self.stderr = err
|
||||
if rc != 0:
|
||||
self.module.fail_json(
|
||||
msg="Container %s exited with code %s when %sed"
|
||||
% (self.name, rc, action),
|
||||
msg="Container %s exited with code %s when %sed" % (self.name, rc, action),
|
||||
stdout=out,
|
||||
stderr=err,
|
||||
)
|
||||
|
|
@ -1858,18 +1780,12 @@ class PodmanManager:
|
|||
}
|
||||
self.module_params = params
|
||||
self.name = self.module_params["name"]
|
||||
self.executable = self.module.get_bin_path(
|
||||
self.module_params["executable"], required=True
|
||||
)
|
||||
self.executable = self.module.get_bin_path(self.module_params["executable"], required=True)
|
||||
self.image = self.module_params["image"]
|
||||
self.state = self.module_params["state"]
|
||||
disable_image_pull = (
|
||||
self.state in ("quadlet", "absent") or self.module_params["pull"] == "never"
|
||||
)
|
||||
disable_image_pull = self.state in ("quadlet", "absent") or self.module_params["pull"] == "never"
|
||||
image_actions = (
|
||||
ensure_image_exists(self.module, self.image, self.module_params)
|
||||
if not disable_image_pull
|
||||
else []
|
||||
ensure_image_exists(self.module, self.image, self.module_params) if not disable_image_pull else []
|
||||
)
|
||||
self.results["actions"] += image_actions
|
||||
|
||||
|
|
@ -1903,9 +1819,7 @@ class PodmanManager:
|
|||
self.results.update({"diff": self.container.diff})
|
||||
if self.module.params["debug"] or self.module_params["debug"]:
|
||||
self.results.update({"podman_version": self.container.version})
|
||||
sysd = generate_systemd(
|
||||
self.module, self.module_params, self.name, self.container.version
|
||||
)
|
||||
sysd = generate_systemd(self.module, self.module_params, self.name, self.container.version)
|
||||
self.results["changed"] = changed or sysd["changed"]
|
||||
self.results.update({"podman_systemd": sysd["systemd"]})
|
||||
if sysd["diff"]:
|
||||
|
|
@ -1922,9 +1836,7 @@ class PodmanManager:
|
|||
"""Run actions if desired state is 'started'."""
|
||||
if not self.image:
|
||||
if not self.container.exists:
|
||||
self.module.fail_json(
|
||||
msg="Cannot start container when image" " is not specified!"
|
||||
)
|
||||
self.module.fail_json(msg="Cannot start container when image" " is not specified!")
|
||||
if self.restart:
|
||||
self.container.restart()
|
||||
self.results["actions"].append("restarted %s" % self.container.name)
|
||||
|
|
@ -1974,9 +1886,7 @@ class PodmanManager:
|
|||
def make_created(self):
|
||||
"""Run actions if desired state is 'created'."""
|
||||
if not self.container.exists and not self.image:
|
||||
self.module.fail_json(
|
||||
msg="Cannot create container when image" " is not specified!"
|
||||
)
|
||||
self.module.fail_json(msg="Cannot create container when image" " is not specified!")
|
||||
if not self.container.exists:
|
||||
self.container.create()
|
||||
self.results["actions"].append("created %s" % self.container.name)
|
||||
|
|
@ -2006,9 +1916,7 @@ class PodmanManager:
|
|||
def make_stopped(self):
|
||||
"""Run actions if desired state is 'stopped'."""
|
||||
if not self.container.exists and not self.image:
|
||||
self.module.fail_json(
|
||||
msg="Cannot create container when image" " is not specified!"
|
||||
)
|
||||
self.module.fail_json(msg="Cannot create container when image" " is not specified!")
|
||||
if not self.container.exists:
|
||||
self.container.create()
|
||||
self.results["actions"].append("created %s" % self.container.name)
|
||||
|
|
@ -2028,9 +1936,7 @@ class PodmanManager:
|
|||
if not self.container.exists:
|
||||
self.results.update({"changed": False})
|
||||
elif self.container.exists:
|
||||
delete_systemd(
|
||||
self.module, self.module_params, self.name, self.container.version
|
||||
)
|
||||
delete_systemd(self.module, self.module_params, self.name, self.container.version)
|
||||
self.container.delete()
|
||||
self.results["actions"].append("deleted %s" % self.container.name)
|
||||
self.results.update({"changed": True})
|
||||
|
|
|
|||
|
|
@ -78,9 +78,7 @@ ARGUMENTS_SPEC_POD = dict(
|
|||
memory_swap=dict(type="str", required=False),
|
||||
name=dict(type="str", required=True),
|
||||
network=dict(type="list", elements="str", required=False),
|
||||
network_alias=dict(
|
||||
type="list", elements="str", required=False, aliases=["network_aliases"]
|
||||
),
|
||||
network_alias=dict(type="list", elements="str", required=False, aliases=["network_aliases"]),
|
||||
no_hosts=dict(type="bool", required=False),
|
||||
pid=dict(type="str", required=False),
|
||||
pod_id_file=dict(type="str", required=False),
|
||||
|
|
@ -157,9 +155,7 @@ class PodmanPodModuleParams:
|
|||
def _create_action(self):
|
||||
cmd = [self.action]
|
||||
all_param_methods = [
|
||||
func
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func)) and func.startswith("addparam")
|
||||
func for func in dir(self) if callable(getattr(self, func)) and func.startswith("addparam")
|
||||
]
|
||||
params_set = (i for i in self.params if self.params[i] is not None)
|
||||
for param in params_set:
|
||||
|
|
@ -172,14 +168,12 @@ class PodmanPodModuleParams:
|
|||
if minv and LooseVersion(minv) > LooseVersion(self.podman_version):
|
||||
self.module.fail_json(
|
||||
msg="Parameter %s is supported from podman "
|
||||
"version %s only! Current version is %s"
|
||||
% (param, minv, self.podman_version)
|
||||
"version %s only! Current version is %s" % (param, minv, self.podman_version)
|
||||
)
|
||||
if maxv and LooseVersion(maxv) < LooseVersion(self.podman_version):
|
||||
self.module.fail_json(
|
||||
msg="Parameter %s is supported till podman "
|
||||
"version %s only! Current version is %s"
|
||||
% (param, minv, self.podman_version)
|
||||
"version %s only! Current version is %s" % (param, minv, self.podman_version)
|
||||
)
|
||||
|
||||
def addparam_add_host(self, c):
|
||||
|
|
@ -459,9 +453,7 @@ class PodmanPodDiff:
|
|||
|
||||
"""
|
||||
info_config = self.info
|
||||
before, after = diff_generic(
|
||||
self.params, info_config, module_arg, cmd_arg, boolean_type
|
||||
)
|
||||
before, after = diff_generic(self.params, info_config, module_arg, cmd_arg, boolean_type)
|
||||
return self._diff_update_and_compare(module_arg, before, after)
|
||||
|
||||
def diffparam_add_host(self):
|
||||
|
|
@ -643,14 +635,9 @@ class PodmanPodDiff:
|
|||
before = None
|
||||
after = self.params["volume"]
|
||||
if after is not None:
|
||||
after = [
|
||||
":".join([clean_volume(i) for i in v.split(":")[:2]])
|
||||
for v in self.params["volume"]
|
||||
]
|
||||
after = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in self.params["volume"]]
|
||||
if before is not None:
|
||||
before = [
|
||||
":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before
|
||||
]
|
||||
before = [":".join([clean_volume(i) for i in v.split(":")[:2]]) for v in before]
|
||||
self.module.log("PODMAN Before: %s and After: %s" % (before, after))
|
||||
if before is None and after is None:
|
||||
return self._diff_update_and_compare("volume", before, after)
|
||||
|
|
@ -664,11 +651,7 @@ class PodmanPodDiff:
|
|||
return self._diff_generic("volumes_from", "--volumes-from")
|
||||
|
||||
def is_different(self):
|
||||
diff_func_list = [
|
||||
func
|
||||
for func in dir(self)
|
||||
if callable(getattr(self, func)) and func.startswith("diffparam")
|
||||
]
|
||||
diff_func_list = [func for func in dir(self) if callable(getattr(self, func)) and func.startswith("diffparam")]
|
||||
fail_fast = not bool(self.module._diff)
|
||||
different = False
|
||||
for func_name in diff_func_list:
|
||||
|
|
@ -720,24 +703,12 @@ class PodmanPod:
|
|||
@property
|
||||
def different(self):
|
||||
"""Check if pod is different."""
|
||||
diffcheck = PodmanPodDiff(
|
||||
self.module, self.module_params, self.info, self.infra_info, self.version
|
||||
)
|
||||
diffcheck = PodmanPodDiff(self.module, self.module_params, self.info, self.infra_info, self.version)
|
||||
is_different = diffcheck.is_different()
|
||||
diffs = diffcheck.diff
|
||||
if self.module._diff and is_different and diffs["before"] and diffs["after"]:
|
||||
self.diff["before"] = (
|
||||
"\n".join(
|
||||
["%s - %s" % (k, v) for k, v in sorted(diffs["before"].items())]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
self.diff["after"] = (
|
||||
"\n".join(
|
||||
["%s - %s" % (k, v) for k, v in sorted(diffs["after"].items())]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
self.diff["before"] = "\n".join(["%s - %s" % (k, v) for k, v in sorted(diffs["before"].items())]) + "\n"
|
||||
self.diff["after"] = "\n".join(["%s - %s" % (k, v) for k, v in sorted(diffs["after"].items())]) + "\n"
|
||||
return is_different
|
||||
|
||||
@property
|
||||
|
|
@ -771,9 +742,7 @@ class PodmanPod:
|
|||
def get_info(self):
|
||||
"""Inspect pod and gather info about it."""
|
||||
# pylint: disable=unused-variable
|
||||
rc, out, err = self.module.run_command(
|
||||
[self.module_params["executable"], b"pod", b"inspect", self.name]
|
||||
)
|
||||
rc, out, err = self.module.run_command([self.module_params["executable"], b"pod", b"inspect", self.name])
|
||||
if rc == 0:
|
||||
info = json.loads(out)
|
||||
# from podman 5 onwards, this is a list of dicts,
|
||||
|
|
@ -812,20 +781,14 @@ class PodmanPod:
|
|||
else:
|
||||
return {}
|
||||
# pylint: disable=unused-variable
|
||||
rc, out, err = self.module.run_command(
|
||||
[self.module_params["executable"], b"inspect", infra_container_id]
|
||||
)
|
||||
rc, out, err = self.module.run_command([self.module_params["executable"], b"inspect", infra_container_id])
|
||||
return json.loads(out)[0] if rc == 0 else {}
|
||||
|
||||
def _get_podman_version(self):
|
||||
# pylint: disable=unused-variable
|
||||
rc, out, err = self.module.run_command(
|
||||
[self.module_params["executable"], b"--version"]
|
||||
)
|
||||
rc, out, err = self.module.run_command([self.module_params["executable"], b"--version"])
|
||||
if rc != 0 or not out or "version" not in out:
|
||||
self.module.fail_json(
|
||||
msg="%s run failed!" % self.module_params["executable"]
|
||||
)
|
||||
self.module.fail_json(msg="%s run failed!" % self.module_params["executable"])
|
||||
return out.split("version")[1].strip()
|
||||
|
||||
def _perform_action(self, action):
|
||||
|
|
@ -841,10 +804,7 @@ class PodmanPod:
|
|||
self.version,
|
||||
self.module,
|
||||
).construct_command_from_params()
|
||||
full_cmd = " ".join(
|
||||
[self.module_params["executable"], "pod"]
|
||||
+ [to_native(i) for i in b_command]
|
||||
)
|
||||
full_cmd = " ".join([self.module_params["executable"], "pod"] + [to_native(i) for i in b_command])
|
||||
self.module.log("PODMAN-POD-DEBUG: %s" % full_cmd)
|
||||
self.actions.append(full_cmd)
|
||||
if not self.module.check_mode:
|
||||
|
|
@ -855,9 +815,7 @@ class PodmanPod:
|
|||
self.stdout = out
|
||||
self.stderr = err
|
||||
if rc != 0:
|
||||
self.module.fail_json(
|
||||
msg="Can't %s pod %s" % (action, self.name), stdout=out, stderr=err
|
||||
)
|
||||
self.module.fail_json(msg="Can't %s pod %s" % (action, self.name), stdout=out, stderr=err)
|
||||
|
||||
def delete(self):
|
||||
"""Delete the pod."""
|
||||
|
|
@ -918,9 +876,7 @@ class PodmanPodManager:
|
|||
"pod": {},
|
||||
}
|
||||
self.name = self.module_params["name"]
|
||||
self.executable = self.module.get_bin_path(
|
||||
self.module_params["executable"], required=True
|
||||
)
|
||||
self.executable = self.module.get_bin_path(self.module_params["executable"], required=True)
|
||||
self.state = self.module_params["state"]
|
||||
self.recreate = self.module_params["recreate"]
|
||||
self.pod = PodmanPod(self.module, self.name, self.module_params)
|
||||
|
|
@ -945,9 +901,7 @@ class PodmanPodManager:
|
|||
self.results.update({"diff": self.pod.diff})
|
||||
if self.module.params["debug"] or self.module_params["debug"]:
|
||||
self.results.update({"podman_version": self.pod.version})
|
||||
sysd = generate_systemd(
|
||||
self.module, self.module_params, self.name, self.pod.version
|
||||
)
|
||||
sysd = generate_systemd(self.module, self.module_params, self.name, self.pod.version)
|
||||
self.results["changed"] = changed or sysd["changed"]
|
||||
self.results.update({"podman_systemd": sysd["systemd"]})
|
||||
if sysd["diff"]:
|
||||
|
|
|
|||
|
|
@ -55,14 +55,9 @@ class Quadlet:
|
|||
Construct the quadlet content as a string.
|
||||
"""
|
||||
custom_user_options = self.custom_params.get("quadlet_options")
|
||||
custom_text = (
|
||||
"\n" + "\n".join(custom_user_options) if custom_user_options else ""
|
||||
)
|
||||
custom_text = "\n" + "\n".join(custom_user_options) if custom_user_options else ""
|
||||
return (
|
||||
f"[{self.section}]\n"
|
||||
+ "\n".join(f"{key}={value}" for key, value in self.dict_params)
|
||||
+ custom_text
|
||||
+ "\n"
|
||||
f"[{self.section}]\n" + "\n".join(f"{key}={value}" for key, value in self.dict_params) + custom_text + "\n"
|
||||
)
|
||||
|
||||
def write_to_file(self, path: str):
|
||||
|
|
@ -167,9 +162,7 @@ class ContainerQuadlet(Quadlet):
|
|||
"""
|
||||
# Work on params in params_map and convert them to a right form
|
||||
if params["annotation"]:
|
||||
params["annotation"] = [
|
||||
"%s=%s" % (k, v) for k, v in params["annotation"].items()
|
||||
]
|
||||
params["annotation"] = ["%s=%s" % (k, v) for k, v in params["annotation"].items()]
|
||||
if params["cap_add"]:
|
||||
params["cap_add"] = " ".join(params["cap_add"])
|
||||
if params["cap_drop"]:
|
||||
|
|
@ -181,22 +174,16 @@ class ContainerQuadlet(Quadlet):
|
|||
else params["command"]
|
||||
)
|
||||
if params["label"]:
|
||||
params["label"] = [
|
||||
shlex.quote("%s=%s" % (k, v)) for k, v in params["label"].items()
|
||||
]
|
||||
params["label"] = [shlex.quote("%s=%s" % (k, v)) for k, v in params["label"].items()]
|
||||
if params["env"]:
|
||||
params["env"] = [
|
||||
shlex.quote("%s=%s" % (k, v)) for k, v in params["env"].items()
|
||||
]
|
||||
params["env"] = [shlex.quote("%s=%s" % (k, v)) for k, v in params["env"].items()]
|
||||
if params["rootfs"]:
|
||||
params["rootfs"] = params["image"]
|
||||
params["image"] = None
|
||||
if params["sysctl"]:
|
||||
params["sysctl"] = ["%s=%s" % (k, v) for k, v in params["sysctl"].items()]
|
||||
if params["tmpfs"]:
|
||||
params["tmpfs"] = [
|
||||
"%s:%s" % (k, v) if v else k for k, v in params["tmpfs"].items()
|
||||
]
|
||||
params["tmpfs"] = ["%s:%s" % (k, v) if v else k for k, v in params["tmpfs"].items()]
|
||||
|
||||
# Work on params which are not in the param_map but can be calculated
|
||||
params["global_args"] = []
|
||||
|
|
@ -227,10 +214,7 @@ class ContainerQuadlet(Quadlet):
|
|||
if params["blkio_weight_device"]:
|
||||
params["podman_args"].append(
|
||||
" ".join(
|
||||
[
|
||||
f"--blkio-weight-device {':'.join(blkio)}"
|
||||
for blkio in params["blkio_weight_device"].items()
|
||||
]
|
||||
[f"--blkio-weight-device {':'.join(blkio)}" for blkio in params["blkio_weight_device"].items()]
|
||||
)
|
||||
)
|
||||
if params["cgroupns"]:
|
||||
|
|
@ -265,9 +249,7 @@ class ContainerQuadlet(Quadlet):
|
|||
if params["decryption_key"]:
|
||||
params["podman_args"].append(f"--decryption-key {params['decryption_key']}")
|
||||
if params["device_cgroup_rule"]:
|
||||
params["podman_args"].append(
|
||||
f"--device-cgroup-rule {params['device_cgroup_rule']}"
|
||||
)
|
||||
params["podman_args"].append(f"--device-cgroup-rule {params['device_cgroup_rule']}")
|
||||
if params["device_read_bps"]:
|
||||
for i in params["device_read_bps"]:
|
||||
params["podman_args"].append(f"--device-read-bps {i}")
|
||||
|
|
@ -281,9 +263,7 @@ class ContainerQuadlet(Quadlet):
|
|||
for i in params["device_write_iops"]:
|
||||
params["podman_args"].append(f"--device-write-iops {i}")
|
||||
if params["etc_hosts"]:
|
||||
params["etc_hosts"] = [
|
||||
"%s:%s" % (k, v) for k, v in params["etc_hosts"].items()
|
||||
]
|
||||
params["etc_hosts"] = ["%s:%s" % (k, v) for k, v in params["etc_hosts"].items()]
|
||||
if params["env_merge"]:
|
||||
for k, v in params["env_merge"].items():
|
||||
params["podman_args"].append(f"--env {k}={v}")
|
||||
|
|
@ -314,32 +294,24 @@ class ContainerQuadlet(Quadlet):
|
|||
params["podman_args"].append(f"--label-file {params['label_file']}")
|
||||
if params["log_opt"]:
|
||||
params["log_opt"] = [
|
||||
"%s=%s" % (k.replace("max_size", "max-size"), v)
|
||||
for k, v in params["log_opt"].items()
|
||||
if v is not None
|
||||
"%s=%s" % (k.replace("max_size", "max-size"), v) for k, v in params["log_opt"].items() if v is not None
|
||||
]
|
||||
if params["mac_address"]:
|
||||
params["podman_args"].append(f"--mac-address {params['mac_address']}")
|
||||
if params["memory"]:
|
||||
params["podman_args"].append(f"--memory {params['memory']}")
|
||||
if params["memory_reservation"]:
|
||||
params["podman_args"].append(
|
||||
f"--memory-reservation {params['memory_reservation']}"
|
||||
)
|
||||
params["podman_args"].append(f"--memory-reservation {params['memory_reservation']}")
|
||||
if params["memory_swap"]:
|
||||
params["podman_args"].append(f"--memory-swap {params['memory_swap']}")
|
||||
if params["memory_swappiness"]:
|
||||
params["podman_args"].append(
|
||||
f"--memory-swappiness {params['memory_swappiness']}"
|
||||
)
|
||||
params["podman_args"].append(f"--memory-swappiness {params['memory_swappiness']}")
|
||||
if params["no_healthcheck"]:
|
||||
params["podman_args"].append("--no-healthcheck")
|
||||
if params["no_hosts"] is not None:
|
||||
params["podman_args"].append(f"--no-hosts={params['no_hosts']}")
|
||||
if params["oom_kill_disable"]:
|
||||
params["podman_args"].append(
|
||||
f"--oom-kill-disable={params['oom_kill_disable']}"
|
||||
)
|
||||
params["podman_args"].append(f"--oom-kill-disable={params['oom_kill_disable']}")
|
||||
if params["oom_score_adj"]:
|
||||
params["podman_args"].append(f"--oom-score-adj {params['oom_score_adj']}")
|
||||
if params["os"]:
|
||||
|
|
@ -385,9 +357,7 @@ class ContainerQuadlet(Quadlet):
|
|||
for security_opt in params["security_opt"]:
|
||||
params["podman_args"].append(f"--security-opt {security_opt}")
|
||||
if params["shm_size_systemd"]:
|
||||
params["podman_args"].append(
|
||||
f"--shm-size-systemd {params['shm_size_systemd']}"
|
||||
)
|
||||
params["podman_args"].append(f"--shm-size-systemd {params['shm_size_systemd']}")
|
||||
if params["sig_proxy"]:
|
||||
params["podman_args"].append(f"--sig-proxy {params['sig_proxy']}")
|
||||
if params["systemd"]:
|
||||
|
|
@ -395,9 +365,7 @@ class ContainerQuadlet(Quadlet):
|
|||
if params["timeout"]:
|
||||
params["podman_args"].append(f"--timeout {params['timeout']}")
|
||||
if params["tls_verify"]:
|
||||
params["podman_args"].append(
|
||||
f"--tls-verify={str(params['tls_verify']).lower()}"
|
||||
)
|
||||
params["podman_args"].append(f"--tls-verify={str(params['tls_verify']).lower()}")
|
||||
if params["tty"]:
|
||||
params["podman_args"].append("--tty")
|
||||
if params["umask"]:
|
||||
|
|
@ -493,10 +461,7 @@ class PodQuadlet(Quadlet):
|
|||
if params["blkio_weight_device"]:
|
||||
params["podman_args"].append(
|
||||
" ".join(
|
||||
[
|
||||
f"--blkio-weight-device {':'.join(blkio)}"
|
||||
for blkio in params["blkio_weight_device"].items()
|
||||
]
|
||||
[f"--blkio-weight-device {':'.join(blkio)}" for blkio in params["blkio_weight_device"].items()]
|
||||
)
|
||||
)
|
||||
if params["cpuset_cpus"]:
|
||||
|
|
@ -539,9 +504,7 @@ class PodQuadlet(Quadlet):
|
|||
if params["infra_command"]:
|
||||
params["podman_args"].append(f"--infra-command {params['infra_command']}")
|
||||
if params["infra_conmon_pidfile"]:
|
||||
params["podman_args"].append(
|
||||
f"--infra-conmon-pidfile {params['infra_conmon_pidfile']}"
|
||||
)
|
||||
params["podman_args"].append(f"--infra-conmon-pidfile {params['infra_conmon_pidfile']}")
|
||||
if params["infra_image"]:
|
||||
params["podman_args"].append(f"--infra-image {params['infra_image']}")
|
||||
if params["infra_name"]:
|
||||
|
|
@ -575,15 +538,11 @@ class PodQuadlet(Quadlet):
|
|||
if params["share"]:
|
||||
params["podman_args"].append(f"--share {params['share']}")
|
||||
if params["share_parent"] is not None:
|
||||
params["podman_args"].append(
|
||||
f"--share-parent={str(params['share_parent']).lower()}"
|
||||
)
|
||||
params["podman_args"].append(f"--share-parent={str(params['share_parent']).lower()}")
|
||||
if params["shm_size"]:
|
||||
params["podman_args"].append(f"--shm-size {params['shm_size']}")
|
||||
if params["shm_size_systemd"]:
|
||||
params["podman_args"].append(
|
||||
f"--shm-size-systemd {params['shm_size_systemd']}"
|
||||
)
|
||||
params["podman_args"].append(f"--shm-size-systemd {params['shm_size_systemd']}")
|
||||
if params["subgidname"]:
|
||||
params["podman_args"].append(f"--subgidname {params['subgidname']}")
|
||||
if params["subuidname"]:
|
||||
|
|
@ -722,9 +681,7 @@ def check_quadlet_directory(module, quadlet_dir):
|
|||
except Exception as e:
|
||||
module.fail_json(msg="Directory for quadlet_file can't be created: %s" % e)
|
||||
if not os.access(quadlet_dir, os.W_OK):
|
||||
module.fail_json(
|
||||
msg="Directory for quadlet_file is not writable: %s" % quadlet_dir
|
||||
)
|
||||
module.fail_json(msg="Directory for quadlet_file is not writable: %s" % quadlet_dir)
|
||||
|
||||
|
||||
def create_quadlet_state(module, issuer):
|
||||
|
|
@ -747,9 +704,7 @@ def create_quadlet_state(module, issuer):
|
|||
quadlet_dir = os.path.expanduser(QUADLET_NON_ROOT_PATH)
|
||||
# Create a filename based on the issuer
|
||||
if not module.params.get("name") and not module.params.get("quadlet_filename"):
|
||||
module.fail_json(
|
||||
msg=f"Filename for {issuer} is required for creating a quadlet file."
|
||||
)
|
||||
module.fail_json(msg=f"Filename for {issuer} is required for creating a quadlet file.")
|
||||
if issuer == "image":
|
||||
name = module.params["name"].split("/")[-1].split(":")[0]
|
||||
else:
|
||||
|
|
@ -779,24 +734,14 @@ def create_quadlet_state(module, issuer):
|
|||
results_update = {
|
||||
"changed": True,
|
||||
"diff": {
|
||||
"before": (
|
||||
"\n".join(file_diff[0])
|
||||
if isinstance(file_diff[0], list)
|
||||
else file_diff[0] + "\n"
|
||||
),
|
||||
"after": (
|
||||
"\n".join(file_diff[1])
|
||||
if isinstance(file_diff[1], list)
|
||||
else file_diff[1] + "\n"
|
||||
),
|
||||
"before": ("\n".join(file_diff[0]) if isinstance(file_diff[0], list) else file_diff[0] + "\n"),
|
||||
"after": ("\n".join(file_diff[1]) if isinstance(file_diff[1], list) else file_diff[1] + "\n"),
|
||||
},
|
||||
}
|
||||
else:
|
||||
# adjust file permissions
|
||||
diff = {}
|
||||
if mode is not None and module.set_mode_if_different(
|
||||
quadlet_file_path, mode, False, diff
|
||||
):
|
||||
if mode is not None and module.set_mode_if_different(quadlet_file_path, mode, False, diff):
|
||||
results_update = {"changed": True, "diff": diff}
|
||||
else:
|
||||
results_update = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue