From ebfe00d1a45e8d4cb454908fc5ef77af2f86df14 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sun, 23 Apr 2023 09:34:10 +0200 Subject: [PATCH] added an example unitfile --- plugins/modules/unit.py.example | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 plugins/modules/unit.py.example diff --git a/plugins/modules/unit.py.example b/plugins/modules/unit.py.example new file mode 100644 index 0000000..fe5ea70 --- /dev/null +++ b/plugins/modules/unit.py.example @@ -0,0 +1,43 @@ +#!/usr/bin/python3 +import pathlib +from typing import List, Union + +try: + from ansible_collections.sebastian.systemd.plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modpec + from ansible_collections.sebastian.systemd.plugins.module_utils.module import SystemdReloadMixin, SystemdUnitModule, installable +except ImportError: + from plugins.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modspec + from plugins.module_utils.module import SystemdReloadMixin, SystemdUnitModule, installable + + +@installable +class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore + """Creates units""" + + name = "unit" + module_spec = modspec(argument_spec=dict(name=Types.str(required=True, help="Name of the unit"),)) + + def prepare(self): + self.unitfile = (SYSTEMD_SERVICE_CONFIG / self.get("name")).with_suffix(".") + self.__unit = None + + def body(self): + section = "[]\n" + return section + + def unit(self) -> str: + if self.__unit is None: + self.__unit = "\n".join( + ( + self.header(), + self.body(), + self.install(), + ) + ) + return self.__unit + + +DOCUMENTATION = """""" + +if __name__ == "__main__": + Module()()