ez_docker/plugins/modules/compose.py
2024-12-12 18:03:49 +01:00

79 lines
1.7 KiB
Python

# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
# MIT License (see LICENSE)
from __future__ import annotations
from typing import Any
from ansible.module_utils.basic import AnsibleModule # type: ignore[reportMissingStubFile]
from ansible_collections.ssnailed.ez_compose.plugins.module_utils import ( # type: ignore[reportMissingStubFile]
common,
label,
service,
)
def label_argument_spec() -> dict[str, Any]:
label_args: dict[str, Any] = {
"type": "dict",
"options": {},
}
for module in label.__all__:
if module == "common":
continue
options = {
**label.common.BASE_ARGS,
**getattr(label, module).EXTRA_ARGS,
}
label_args["options"][module] = {
"type": "dict",
"options": options,
}
return label_args
def service_argument_spec() -> dict[str, Any]:
service_args: dict[str, Any] = {
"type": "dict",
"options": {},
"required": True,
}
for module in service.__all__:
if module == "common":
continue
options = {
**service.common.BASE_ARGS,
**getattr(service, module).EXTRA_ARGS,
}
if module == "custom":
options["label_helpers"] = label_argument_spec()
service_args["options"][module] = {
"type": "list",
"elements": "dict",
"options": options,
}
return service_args
def main() -> None:
module = AnsibleModule(
argument_spec={
**common.BASE_ARGS,
"services": service_argument_spec(),
},
)
state = common.get_state(module)
if __name__ == "__main__":
main()