Commits vergleichen

..

Keine gemeinsamen Commits. „d82a902043039592dd5d00ba114b40cfc79e5e8f“ und „9045e51c231afff19fe193945f3b8972cecc88ba“ haben vollständig unterschiedliche Historien.

2 geänderte Dateien mit 44 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -124,7 +124,8 @@ class Types(metaclass=meta):
f"helptext of option {name} is unset." f"helptext of option {name} is unset."
" Ansible requires suboptions to have an documentation" " Ansible requires suboptions to have an documentation"
) )
elif "choices" in elements: elif elements["type"] == "list":
if "choices" in elements:
option["choices"] = elements["choices"] option["choices"] = elements["choices"]
if default is not None: if default is not None:
option["default"] = default option["default"] = default

Datei anzeigen

@ -1,9 +1,9 @@
import pathlib import pathlib
from copy import deepcopy from copy import deepcopy
from typing import Any, Callable, ClassVar, Dict, NoReturn, Optional, Type, TypedDict, TypeVar, Union, overload, Generic from typing import (Any, Callable, ClassVar, Dict, NoReturn, Optional, Type,
TypedDict, TypeVar, Union, overload)
import ansible.module_utils.basic as basic import ansible.module_utils.basic as basic
import os
import shutil
from .generic import AnsibleParameter, Types, systemdbool from .generic import AnsibleParameter, Types, systemdbool
@ -18,11 +18,11 @@ __all__ = (
T = TypeVar("T") T = TypeVar("T")
class TypedDiff(Generic[T], TypedDict, total=False): class TypedDiff(TypedDict):
before: T before: str
after: T after: str
before_header: str before_header: Optional[str]
after_header: str after_header: Optional[str]
def docify(input: Union[dict, AnsibleParameter]) -> dict: def docify(input: Union[dict, AnsibleParameter]) -> dict:
@ -78,7 +78,6 @@ class AnsibleModule(object):
specs["argument_spec"].update(modspec["argument_spec"]) specs["argument_spec"].update(modspec["argument_spec"])
del modspec["argument_spec"] del modspec["argument_spec"]
specs.update(modspec) specs.update(modspec)
self.modspec = specs
self.module = basic.AnsibleModule(**specs) self.module = basic.AnsibleModule(**specs)
self.tmpdir = pathlib.Path(self.module.tmpdir) self.tmpdir = pathlib.Path(self.module.tmpdir)
@ -115,7 +114,7 @@ class AnsibleModule(object):
if diff is not None and not any((before is not None, after is not None)): if diff is not None and not any((before is not None, after is not None)):
pass pass
elif all((before is not None, after is not None, diff is None)): elif all((before is not None, after is not None, diff is None)):
diff = TypedDiff( diff = dict(
before=before, before=before,
after=after, after=after,
) )
@ -207,24 +206,6 @@ class AnsibleModule(object):
"""Wrapper for AnsibleModule.exit_json""" """Wrapper for AnsibleModule.exit_json"""
self.module.exit_json(**self.result) self.module.exit_json(**self.result)
def move_file(self, path: pathlib.Path, dest: pathlib.Path, backup: bool = False, unsafe_writes: bool = False):
"""Moves an Temporary file to an destination it uses the args from add_file_common_args when used
Args:
path: The Path that the file currently is
dest: the location the file should be
backup: should an backup be made before the file is moved
"""
if backup:
shutil.copy2(dest, dest.with_suffix(dest.suffix + ".bak"), follow_symlinks=False)
self.module.atomic_move(path, dest, unsafe_writes=unsafe_writes, keep_dest_attrs=True)
if "add_file_common_args" in self.modspec and self.modspec["add_file_common_args"]:
file_args = self.module.load_file_common_arguments(self.params, path=dest)
diff = TypedDiff()
self.changed |= self.module.set_fs_attributes_if_different(file_args, diff=diff)
self.diff(diff)
class SystemdUnitModule(AnsibleModule): class SystemdUnitModule(AnsibleModule):
#: path of the unitfile managed by this module #: path of the unitfile managed by this module
@ -305,6 +286,34 @@ class SystemdUnitModule(AnsibleModule):
path = self.tmpdir / "newunit" path = self.tmpdir / "newunit"
with open(path, "w") as unit: with open(path, "w") as unit:
unit.write(self.unit()) unit.write(self.unit())
self.module.set_owner_if_different(path.as_posix(), "root", False)
self.module.set_group_if_different(path.as_posix(), "root", False)
self.module.set_mode_if_different(path.as_posix(), "0644", False)
if self.unitfile.exists():
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_owner_if_different(
self.unitfile.as_posix(),
"root",
self.result["changed"],
diff,
)
self.diff(diff)
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_group_if_different(
self.unitfile.as_posix(),
"root",
self.result["changed"],
diff,
)
self.diff(diff)
diff = TypedDiff() # type:ignore[reportCallIssue]
self.changed = self.changed | self.module.set_mode_if_different(
self.unitfile.as_posix(),
"0644",
self.result["changed"],
diff,
)
self.diff(diff)
def check(self): # pragma: nocover def check(self): # pragma: nocover
self.set("unitfile", self.unitfile.as_posix()) self.set("unitfile", self.unitfile.as_posix())
@ -325,7 +334,10 @@ class SystemdUnitModule(AnsibleModule):
self.check() self.check()
if not self.changed: if not self.changed:
return return
self.move_file(self.tmpdir / "newunit", self.unitfile) self.module.atomic_move(
src=(self.tmpdir / "newunit").as_posix(),
dest=self.unitfile.as_posix(),
)
if hasattr(self, "post") and self.post is not None: if hasattr(self, "post") and self.post is not None:
self.post() self.post()