Debian Codegraph @

ansible_collections/community/general/plugins/module_utils/_nomad.py

raw
1 # Copyright (c) 2026, Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
6 # Do not use this from other collections or standalone plugins/modules!
7
8 from __future__ import annotations
9
10 import typing as t
11
12 from ansible_collections.community.general.plugins.module_utils import _deps as deps
13
14 nomad: t.Any = None
15 with deps.declare("python-nomad"):
16 import nomad # type: ignore[no-redef]
17
18 if t.TYPE_CHECKING:
19 from ansible.module_utils.basic import AnsibleModule
20
21 argument_spec = dict(
22 host=dict(required=True, type="str"),
23 port=dict(type="int", default=4646),
24 use_ssl=dict(type="bool", default=True),
25 timeout=dict(type="int", default=5),
26 validate_certs=dict(type="bool", default=True),
27 client_cert=dict(type="path"),
28 client_key=dict(type="path"),
29 namespace=dict(type="str"),
30 token=dict(type="str", no_log=True),
31 )
32
33
34 def setup_nomad_client(module: AnsibleModule) -> nomad.Nomad:
35 deps.validate(module)
36
37 certificate_ssl = (module.params["client_cert"], module.params["client_key"])
38
39 return nomad.Nomad(
40 host=module.params["host"],
41 port=module.params["port"],
42 secure=module.params["use_ssl"],
43 timeout=module.params["timeout"],
44 verify=module.params["validate_certs"],
45 cert=certificate_ssl,
46 namespace=module.params["namespace"],
47 token=module.params["token"],
48 )