File

The file resource manages files and directories, including their content, ownership, and permissions.

Warning

Use absolute file paths and primary group names.

- file:
    - /etc/motd:
        ensure: present
        content: |
          Managed by CCM {{ now() }}
        owner: root
        group: root
        mode: "0644"
ccm ensure file /etc/motd --source /tmp/ccm/motd --owner root --group root --mode 0644
{
  "protocol": "io.choria.ccm.v1.resource.ensure.request",
  "type": "file",
  "properties": {
    "name": "/etc/motd",
    "ensure": "present",
    "content": "Managed by CCM\n",
    "owner": "root",
    "group": "root",
    "mode": "0644"
  }
}

This creates /etc/motd with the given content, parsed through the template engine, and sets ownership and permissions.

Ensure values

ValueDescription
presentThe file must exist
absentThe file must not exist
directoryThe path must be a directory

Properties

PropertyDescription
nameAbsolute path to the file
ensureDesired state (present, absent, directory)
contentFile contents, parsed through the template engine
sourceCopy contents from another local file
ownerFile owner (username)
groupFile group (group name)
modeFile permissions in octal notation (e.g., "0644"). For directories, the execute bit is added automatically to any permission triad that has read or write bits (e.g., "0644" becomes "0755")
providerForce a specific provider (posix only)