1
0
Fork 0
ansible-systemd/plugins/modules/unit.py.example

48 Zeilen
1.3 KiB
Plaintext

2023-04-23 07:34:10 +00:00
#!/usr/bin/python3
import pathlib
from typing import List, Union
2024-02-11 13:35:00 +00:00
try:
2024-02-11 13:39:52 +00:00
from ansible_module.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modpec
from ansible_module.module_utils.module import SystemdReloadMixin, SystemdUnitModule, installable
2024-02-11 13:35:00 +00:00
except ImportError:
from ansible.module_utils.sebastian.base.module_utils.generic import SYSTEMD_SERVICE_CONFIG, Types, modpec
from ansible.module_utils.sebastian.base.module_utils.module import SystemdReloadMixin, SystemdUnitModule, installable
2023-04-23 07:34:10 +00:00
@installable
2024-02-11 13:35:00 +00:00
class Module(SystemdUnitModule, SystemdReloadMixin): # type: ignore
2023-04-23 07:34:10 +00:00
"""Creates units"""
name = "unit"
2024-02-11 13:35:00 +00:00
module_spec = modspec(
argument_spec=dict(
name=Types.str(required=True, help="Name of the unit"),
)
)
2023-04-23 07:34:10 +00:00
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()()