module

Krikri::PluginHelpers::CronTable

CronTable - pure logic for managing a named entry inside a crontab-style text file. Ansible's cron module identifies "its" entry by a comment marker line immediately above the schedule line; this module renders that two-line block and knows how to find/replace/remove it inside arbitrary crontab text, entirely without I/O so it's unit-testable with plain strings.

Constants

MARKER_PREFIX = "#Ansible: "

Class methods

env_decl(name : String, value : String) : String

The NAME="value" line cron.py's env: yes path writes (decl is always double-quoted, unlike cronvar's raw assignment).

Source
env_names(text : String) : Array(String)

Every environment-variable name currently assigned in the text, in file order - real cron.py's get_envnames (^\S+= match, the name being everything before the first '='; no comment exclusion, so a commented-out #FOO=bar still counts, exactly like real module), reported as the result's envs field.

Source
job_names(text : String) : Array(String)

Every job name currently marked in the text, in file order - real cron.py's get_jobnames (lines carrying the "#Ansible: " marker contribute the text after it), reported as the module result's jobs field. Unlike CronVar.var_names this reflects the marker comments, not a parse of the schedule lines.

Source
marker(name : String) : String
Source
render_line(schedule : String, job : String, user : String | Nil, disabled : Bool) : String

Renders the entry line itself (schedule + optional user + job), commented out with a leading '#' when disabled.

Source
schedule(minute : String, hour : String, day : String, month : String, weekday : String, special_time : String | Nil) : String

Renders the 5 schedule fields, or a @special_time shorthand that overrides them (matching Ansible's special_time: reboot/daily/etc).

Source
upsert(text : String, name : String, new_line : String | Nil) : Tuple(String, Bool)

Finds/replaces/removes the {marker, entry} block for name inside text. Pass new_line: nil to remove the entry entirely (state: absent, or a name that simply isn't there yet - a no-op). Returns {new_text, changed}.

Source
upsert_env(text : String, name : String, decl : String | Nil, insert_after : String | Nil, insert_before : String | Nil) : Tuple(String, Bool, String | Nil)

Finds/replaces/removes the ENVIRONMENT-VARIABLE assignment(s) for name inside text - cron.py's env: yes code path, which differs from CronVar/cronvar.py's: matching is a plain "^NAME=" line prefix (not shlex tokens), a NEW variable defaults to the TOP of the file, and insertafter/insertbefore name the variable to position against (immediately after/before its first declaring line). Pass decl: nil to remove (state: absent).

Returns {new_text, changed, missing_insert_target}: the third element is the insertafter/insertbefore variable name when it doesn't exist - real cron.py treats that as a hard failure ("Variable named '%s' not found.") rather than cronvar's silent drop, and nothing is written in that case.

Source