module

Krikri::LoopResolver

LoopResolver - Turns Ansible's various with_* loop sources into a flat, order-preserving Array(JSON::Any) of loop items ready to assign to item.

with_fileglob is deliberately NOT handled here: it needs the runtime variable context (to substitute {{ vars }} in the pattern) and the filesystem, so it is resolved by TaskExecutor at execution time instead of by the parser.

Class methods

with_dict(hash : Hash(String, JSON::Any)) : Array(JSON::Any)

with_dict: {a: 1, b: 2} -> [{"key" => "a", "value" => 1}, {"key" => "b", "value" => 2}] Access in a task via item.key / item.value.

Source
with_indexed_items(items : Array(JSON::Any)) : Array(JSON::Any)

with_indexed_items: [x, y] -> [["0", x], ["1", y]] Access in a task via item[0] (index) and item[1] (value).

Source
with_nested(lists : Array(Array(JSON::Any))) : Array(JSON::Any)

with_nested: [[a, b], [x, y]] -> [[a,x], [a,y], [b,x], [b,y]] The first list varies slowest (outermost loop), matching Ansible. Access in a task via item[0], item[1], ...

Source
with_sequence(spec : String) : Array(JSON::Any)

with_sequence: Ansible-style numeric ranges. Accepts either a bare count ("5") or space-separated key=value pairs (start=1 end=10 stride=2 format=host%02d). Defaults: start=1, stride=1 (or -1 when the range runs backwards), format="%d".

Source
with_subelements(list : Array(JSON::Any), subelement : String) : Array(JSON::Any)

with_community.general.flattened: flattens a set of per-source lists into one flat list of items, in order - this module's own copy was dead code (never called from anywhere - grep for LoopResolver. with_flattened before assuming otherwise), and confusingly looked correct despite that. The real, actually-wired-up implementation lives in TaskExecutor#resolve_loop_flattened, which needs the runtime variable context to template each raw source string first (this module's other with_* methods all operate post-templating, already-resolved JSON::Any sources - with_flattened's own sources are usually a mix of literal strings and exactly one {{ var }} reference, so templating can't happen at parse time the way the others above do).

with_subelements(list, subelement_key) - for each dict in list, yield [parent_dict, subelement] pairs for every element of that dict's subelement_key list. Access in a task via item[0] (the parent dict) and item[1] (the subelement). dev-sec os_hardening uses it to iterate the stdout_lines each of several shell/find results.

Source