Skip to content

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

StateMeaning
presentA regular file exists with the declared content (or copied from source), owner, group, and mode.
directoryA directory exists with the declared owner, group, and mode.
symlinkA symlink exists at the declared path pointing at target.
absentThe path does not exist; a file, directory, or symlink there is removed.

Parameters

ParameterTypeRequiredDescription
contentstringInline file content (state present). Mutually exclusive with source.
sourcestringPath to copy content from (state present). Mutually exclusive with content.
modestringPermission bits in octal, quoted, e.g. "0644".
ownerstringOwning user (name or numeric uid).
groupstringOwning group (name or numeric gid).
targetstringyesSymlink 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/myapp

Symlink and removal

file:
  /usr/local/bin/myapp:
    state: symlink
    target: /opt/myapp/bin/myapp
  /etc/myapp/old.conf:
    state: absent

Notes

  • Linux has the full provider; other operating systems get a reduced one.
  • content and source are mutually exclusive on a present file.