GuidesModules
file.touch
Creates an empty file when it is missing, or updates the modification time of an existing file. Modeled after Salt's file.touch module.
Source: pkg/state/modules/file_touch.go
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | No | State ID | Absolute path to the file to touch. path is accepted as an alias. |
makedirs | bool | No | false | Create parent directories (mode 0755) if needed. |
All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.
Check Behavior
- If the file exists, the state reports no changes needed — regardless of its timestamps.
- If the file does not exist, changes are needed.
Apply Behavior
- Creates parent directories when
makedirsis set. - If the file is missing, creates it empty with mode
0644. - If the file already exists (only reached on a force-apply, e.g. via
watch), runs the systemtouchcommand to update its modification time.
Revert Behavior
- If Apply created the file, Revert removes it.
- If Apply only updated the mtime of an existing file, Revert is a no-op (
Changed: false) — the previous timestamp is not restored.
Examples
Direct Execution
zester 'web-01' file.touch /var/run/myapp/.initializedState File
Create a marker file:
/var/lib/myapp/.provisioned:
file.touch:
- makedirs: trueBump a reload trigger whenever config changes:
/etc/myapp/reload-trigger:
file.touch:
- watch:
- "file.managed:/etc/myapp/config.yaml"Divergences from Salt
- The mtime is not refreshed on a normal run when the file already exists. Salt's
file.touchupdates atime/mtime every time it runs; Zester's Check reports an existing file as satisfied, so the timestamp-update path in Apply only executes when the state is force-applied (for example by awatchrequisite). - Salt's
atimeandmtimeparameters (setting explicit timestamps) are not supported.
file.replace
Performs a regular-expression search-and-replace within a file, with optional append/prepend when the pattern is not found. Modeled after Salt's file.replace module.
pkg.installed
Ensures that a system package is installed using the auto-detected package manager. Supports apt, yum, dnf, and brew.