Krikri::InventoryPatterns
The pattern machinery behind Ansible's own inventory_hostnames lookup
plugin - the pure part (a groups hash + pattern terms -> the matched
host names) that BOTH of this project's lookup paths share:
- the hand-rolled evaluator's scalar arm
(VariableSubstitutor::ExpressionEvaluator#lookup_inventory_hostnames,
reached by direct
{{ lookup('inventory_hostnames', ...) }}/{{ query(...) }}text), and - the krikri-jinja engine's registered
lookup/query(KrikriJinjaLookups - the path every legacywith_inventory_hostnames:loop source reaches, because TaskExecutor#resolve_loop_lookup evaluates the source asquery('inventory_hostnames', term, wantlist=True)on the engine, not through the hand-rolled evaluator's own lookup dispatch).
Faithful to the real plugin's OWN implementation, which is simpler
than it looks: it builds a throwaway InventoryManager purely from
variables['groups'] - NOT from the full inventory - and runs the
standard host-pattern machinery over it. The groups magic var is
already in every task's vars context
(TaskExecutor#build_vars_context), so this needs no inventory
plumbing at all. Pattern semantics matched to the Ansible module:
comma-separated (colon fallback) terms, & intersection / !
exclusion applied after the regular terms, fnmatch glob over group
names first and host names only when no group matched (or the
pattern carries glob metacharacters), ~-prefixed raw regexes,
[N]/[A:B] subscripts (the range is INCLUSIVE of B, Ansible's
hosts[start:end + 1]), and a no-match result that is an empty list
- the real lookup swallows its own AnsibleError and returns [], never failing the task.
Class methods
Normalizes the groups magic var into the {group => [hosts]} map
the pattern matcher works over: every named group as-is, all =
the full host list (or the deduped union when the var lacks it),
and ungrouped = the var's own value when present, else every
host in no named group - Ansible's own groups magic var
always carries both implicit groups.
The match of manager.py's _split_host_pattern + order_patterns +
get_hosts term application: regular terms union in order, then
& terms intersect, then ! terms exclude (and a pattern made
ONLY of &/! terms implicitly starts from 'all'). A pattern error
(e.g. an out-of-range subscript inside _match_one_pattern's
AnsibleError) empties the WHOLE result - real LookupModule:
except AnsibleError: return [] - never failing the task.