module

Krikri::RoleLoader

RoleLoader - resolves and loads roles: entries for a play.

A role is a directory (roles/<name>/) with a conventional layout: tasks/main.yml, handlers/main.yml, defaults/main.yml, vars/main.yml, meta/main.yml, files/, templates/

Role search path mirrors Ansible's common case: <playbook_dir>/roles/<name>, then ./roles/<name> relative to the working directory. Ansible also searches ANSIBLE_ROLES_PATH and a few other locations; not implemented.

Class methods

find_main_file(dir : String) : String | Nil

Loads a role's defaults/ or vars/ - real Ansible supports EITHER a single main.yml file OR a main/ directory of multiple *.yml files (same convention tasks/main/ uses), merged together in alphabetical filename order (later files win on a key collision - matching real Ansible's own main/ directory loading, which reads files in sorted order and merges each into the accumulated dict). Only ONE of the two forms is ever present for a given role. Real bug found benchmarking kyl191.openvpn (round 160): its own defaults/main/openvpn.yml (no defaults/main.yml at all) was never read - load_vars_file alone always looked for exactly defaults/main.yml, silently returning an empty hash for a role using the directory form - every one of its own defaults (openvpn_server_network, openvpn_server_ipv6_network, ...) came back undefined, tripping the role's own "fail if both tunnel networks are disabled" validation check that real Ansible never reaches (both are non-empty by default).

Source
load_roles(roles_yaml : Array(YAML::Any), play : Play, playbook_dir : String) : Tuple(Array(Task), Array(Task))

Loads every entry in a play's roles: list (plus their meta/main.yml dependencies, recursively), in order. Returns {tasks, handlers} to prepend to the play - Ansible runs role tasks before the play's own tasks: (pre_tasks:/post_tasks: aren't implemented).

Source
load_single_role(name : String, invocation_vars : Hash(String, JSON::Any), invocation_tags : Array(String), play : Play, playbook_dir : String, tasks_from : String | Nil = nil, parent_names : Array(String) = [] of String, parent_paths : Array(String) = [] of String, parent_defaults : Hash(String, JSON::Any) = Hash(String, JSON::Any).new) : Tuple(Array(Task), Array(Task))

Loads a single role by name (plus its meta/main.yml dependencies) - used by TaskExecutor#execute_include_role for include_role:, the dynamic (execution-time) counterpart to a static roles: entry. Each call gets its own fresh "seen" set, so - matching include_role's allow_duplicates: true default - repeated include_role calls for the same role name each load it again rather than being silently deduplicated the way a role listed twice under roles: would be. allow_duplicates: false on the include itself isn't honored (dedup only happens within a single call's own meta dependency chain).

Source
load_vars_file(path : String) : Hash(String, JSON::Any)

Public: TaskExecutor#execute_include_vars loads the same shape of YAML vars file that roles do, and must parse it identically (including Vault decryption of individual values).

Source
load_vars_file_main(dir : String) : Hash(String, JSON::Any)
Source
role_exists?(name : String, playbook_dir : String) : Bool
Source