1
0
Fork 0
ansible-systemd/plugins/modules/target.py

140 Zeilen
3.8 KiB
Python

2023-04-20 22:22:27 +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, systemdbool
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, systemdbool
from ansible.module_utils.sebastian.base.module_utils.module import SystemdReloadMixin, SystemdUnitModule, installable
2023-04-23 08:32:42 +00:00
__module_name__ = "TargetModule"
2023-04-20 22:22:27 +00:00
@installable
2023-04-23 08:32:42 +00:00
class TargetModule(SystemdUnitModule, SystemdReloadMixin):
2023-04-20 22:22:27 +00:00
"""Creates Target units"""
name = "target"
module_spec = dict(
argument_spec=dict(
2023-04-23 08:32:42 +00:00
description=Types.str(help="description of the target"),
name=Types.str(required=True, help="name of the target"),
allow_isolate=Types.bool(
default=False,
help="allows admins to restrict the system to only start units that are wanted by this unit and subsequent units",
),
2023-04-20 22:22:27 +00:00
),
)
restartable = False
2023-04-20 22:22:27 +00:00
2023-04-21 18:52:00 +00:00
def prepare(self):
2023-04-23 08:32:42 +00:00
self.unitfile = (SYSTEMD_SERVICE_CONFIG / self.get("name")).with_suffix(".target")
2023-04-21 18:56:16 +00:00
self.__unit = None
2023-04-21 18:52:00 +00:00
2023-04-21 18:49:21 +00:00
def header(self) -> str:
section = super().header()
2023-04-23 08:32:42 +00:00
section += "AllowIsolate={}\n".format(systemdbool(self.get("allow_isolate", False)))
2023-04-21 18:49:21 +00:00
return section
2023-04-20 22:22:27 +00:00
def unit(self) -> str:
if self.__unit is None:
self.__unit = "\n".join(
(
self.header(),
self.install(),
)
)
return self.__unit
DOCUMENTATION = """---
description:
- Creates Target units
module: target
options:
after:
default: []
description:
- list of units that this unit wants to be started after this unit
elements: str
required: false
type: list
allow_isolate:
default: false
2023-04-23 08:32:42 +00:00
description:
- allows admins to restrict the system to only start units that are wanted by
this unit and subsequent units
2023-04-20 22:22:27 +00:00
required: false
type: bool
before:
default: []
description:
- list of units that this unit needs to be started before this unit.
elements: str
required: false
type: list
description:
2023-04-23 08:32:42 +00:00
description:
- description of the target
required: false
2023-04-20 22:22:27 +00:00
type: str
documentation:
default: []
description:
- Paths where documentation can be found
elements: str
required: false
type: list
name:
2023-04-23 08:32:42 +00:00
description:
- name of the target
2023-04-20 22:22:27 +00:00
required: true
type: str
partof:
default: []
description:
- list of units that this unit is part of.
- If the restart this unit does it too, but if this restarts it does not affect
the other units.
elements: str
required: false
type: list
required_by:
default: []
description:
- systemd units that require this mount
elements: str
required: false
type: list
requires:
default: []
description:
- list of units that this unit requires. If it fails or can't be started this
unit fails. without before/after this is started at the same time
elements: str
required: false
type: list
wanted_by:
default: []
description:
- systemd units that want the mount, but not explicitly require it. Commonly used
for target if not service explicitly require it.
elements: str
required: false
type: list
wants:
default: []
description:
- list of units that this unit wants. If it fails or can't be started it does
not affect this unit
elements: str
required: false
type: list
short_description: Creates Target units
"""
if __name__ == "__main__":
2023-04-23 08:32:42 +00:00
TargetModule()()