file
Manages a single filesystem path — a regular file (content from inline text or a source), a directory, or a symlink — along with its owner, group, and mode. Idempotent: re-applying an unchanged declaration reports no change.
Category: System & core
States
| State | Meaning |
|---|---|
present | A regular file exists with the declared content (or copied from source), owner, group, and mode. |
directory | A directory exists with the declared owner, group, and mode. |
symlink | A symlink exists at the declared path pointing at target. |
absent | The path does not exist; a file, directory, or symlink there is removed. |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
content | string | Inline file content (state present). Mutually exclusive with source. | |
source | string | Path to copy content from (state present). Mutually exclusive with content. | |
mode | string | Permission bits in octal, quoted, e.g. "0644". | |
owner | string | Owning user (name or numeric uid). | |
group | string | Owning group (name or numeric gid). | |
target | string | yes | Symlink target (state symlink only). |
Examples
Write a config file
file:
/etc/myapp/config.toml:
state: present
content: |
[server]
port = 8080
owner: myapp
group: myapp
mode: "0640"Ensure a directory, then a file inside it
The require requisite orders the file after the directory.
file:
/opt/myapp:
state: directory
mode: "0750"
/opt/myapp/VERSION:
state: present
content: "1.0.0\n"
require:
- file: /opt/myappSymlink and removal
file:
/usr/local/bin/myapp:
state: symlink
target: /opt/myapp/bin/myapp
/etc/myapp/old.conf:
state: absentNotes
- Linux has the full provider; other operating systems get a reduced one.
contentandsourceare mutually exclusive on apresentfile.