73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
# Copyright: (c) 2024, Luca Bilke <luca@bil.ke>
|
|
# MIT License (see LICENSE)
|
|
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
from typing import TYPE_CHECKING
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import (
|
|
finish,
|
|
get_state,
|
|
update_project,
|
|
)
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.service import common as service
|
|
|
|
if TYPE_CHECKING:
|
|
from ansible_collections.snailed.ez_compose.plugins.module_utils.common import State
|
|
|
|
def helper(state: State) -> State:
|
|
project_name = state.module.params["project_name"]
|
|
definition = state.module.params["definition"]
|
|
internal_network = state.module.params.get("internal_network", False)
|
|
|
|
update = copy.deepcopy(definition)
|
|
|
|
networks = update.get("networks", {})
|
|
|
|
if internal_network:
|
|
networks[f"{project_name}_internal"] = None
|
|
|
|
update["networks"] = networks
|
|
|
|
return service.update(state, update)
|
|
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec={
|
|
"project_name": {
|
|
"type": "str",
|
|
"required": True,
|
|
},
|
|
"name": {
|
|
"type": "str",
|
|
"required": True,
|
|
},
|
|
"internal_network": {
|
|
"type": "bool",
|
|
},
|
|
"state": {
|
|
"type": "str",
|
|
"default": "present",
|
|
"choices": ["present", "absent"],
|
|
},
|
|
"definition": {
|
|
"type": "dict",
|
|
"required": True,
|
|
},
|
|
},
|
|
supports_check_mode=True,
|
|
)
|
|
|
|
state = get_state(module)
|
|
|
|
for f in [helper, update_project]:
|
|
state = f(state)
|
|
|
|
finish(state)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|