3. Facts, variables, and ordering
Gather host facts into variables, target steps with conditions, and sequence them with requires.
After this lesson you can
- Gather facts with a gather block and use them in expressions - Skip steps per host with condition - Order dependent steps with requires
Before you start: Your first convergence
A gather block runs a gatherer before any step and binds its result to a name — gather "os" { from = "core.os_info" } makes os.family available to every expression. vars declares your own values (evaluated lazily, so they can reference gathered facts); --var KEY=VALUE overrides either from the CLI.
Steps run in dependency order, not file order: requires draws the edges of a DAG and independent steps may run in parallel. requires is ordering only — it is not a success demand. condition gates a step on an expression; a false condition skips it rather than failing it.
§ 1Exercise: Gate a step on a gathered fact
In the scaffolded playbook, add a variable derived from the os gatherer and a second step that only runs on Linux and requires the first.
gather "os" { from = "core.os_info" }
vars {
is_linux = os.family == "linux"
}
play "baseline" {
step "make-a" {
resource = "core.file_present"
properties { path = "/var/tmp/weave-a.txt" content = "alpha" }
}
step "make-b" {
resource = "core.file_present"
condition = is_linux
requires = ["make-a"]
properties { path = "/var/tmp/weave-b.txt" content = "beta" }
}
}
Expected result
validate stays green; on a Linux host apply configures make-a before make-b, and check shows both. With condition = !is_linux the second step reports skipped instead.
Hint
Variables are lazy — a var referencing os.… only evaluates after gathering, so validate won't run the gatherer.