Skip to content

file

The file module handles file operations between the local machine and remote hosts via SFTP. It supports three modes: copy, template, and fetch.

Upload a local file to the remote host:

file "/etc/nginx/nginx.conf" {
src "files/nginx.conf"
owner "root"
group "root"
mode "0644"
}

Interpolate ${var} placeholders before uploading:

file "/etc/myapp/config.toml" {
src "templates/config.toml"
template #true
owner "appuser"
mode "0600"
}

Download a remote file to the local machine:

file "backups/${host.name}-dump.sql" {
src "/var/backups/db.sql"
fetch #true
}
ParameterTypeDescription
(positional)stringDestination path (remote for copy/template, local for fetch)
srcstringSource file path (required)
templatebooleanInterpolate ${var} placeholders before uploading
fetchbooleanDownload from remote instead of uploading
ownerstringRemote file owner
groupstringRemote file group
modestringRemote file permissions (e.g., "0644")

Copy and template modes compare SHA256 checksums between the local and remote files. If they match, the transfer is skipped. Fetch mode always downloads.

See the web-server example for a template-based nginx deployment.