Debian Codegraph @

ansible_collections/community/general/plugins/plugin_utils/_lookup.py

raw
1 # Copyright (c) 2026 Felix Fontein <[email protected]>
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 plugin 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.errors import AnsibleLookupError
13
14 if t.TYPE_CHECKING:
15 from collections.abc import Mapping, Sequence
16
17 from ansible.plugins.lookup import LookupBase
18
19
20 def check_for_wrong_terms(plugin: LookupBase, *, direct: Mapping[str, t.Any]) -> None:
21 # Note that we don't check "terms" here since the keyword argument "terms"
22 # is mapped by Python to the run() positional argument "terms".
23 for opt in ("_terms",):
24 if opt in direct:
25 raise AnsibleLookupError(
26 f"The {opt!r} keyword argument is not supported, you must provide terms as positional arguments: use"
27 f" lookup({plugin.ansible_name!r}, arg1, arg2) instead of lookup({plugin.ansible_name!r}, {opt}=[arg1, arg2])"
28 )
29
30
31 def check_for_no_terms(plugin: LookupBase, *, terms: Sequence[t.Any], direct: Mapping[str, t.Any]) -> None:
32 if terms:
33 raise AnsibleLookupError("The lookup plugin does not accept positional arguments")
34 # Note that we don't check "terms" here since the keyword argument "terms"
35 # is mapped by Python to the run() positional argument "terms".
36 for opt in ("_terms",):
37 if opt in direct:
38 raise AnsibleLookupError(f"The {opt!r} keyword argument is not supported")