file
manage a file
At most one of content, template, source, copy_from, and stock sets the content. A step without any of them manages only the owner, group, and mode that it gives, of a file that exists. The step creates missing parent directories, owned by root with mode 0755.
Keys
| Key | Type | Default | Meaning |
|---|---|---|---|
path | string | required | absolute |
content | string | - | literal text |
template | string | - | file in the recipe's templates/ |
source | string | - | file in the recipe's files/ |
copy_from | string | - | file on the host |
stock | boolean | false | content that the package ships |
owner | name or ID | root | |
group | name or ID | root | |
mode | string | 0644 | octal, in quotes |
validate | string | - | check command for the new file |
absent | boolean | false | |
replace | boolean | false | remove another kind of thing at path first |
file.path
string, required
Absolute. The step creates missing parent directories, owned by root with mode 0755.
file.content
string
Literal text. A step without content, template, source, copy_from, or stock sets only the owner, group, and mode that it gives, with no defaults, of a file that exists. When that file is missing, the plan says does not exist yet. Apply fails when it is still missing.
file.template
string
File in the recipe's templates/ directory. Its output is the content.
file.source
string
File in the recipe's files/ directory. Its bytes are the content.
file.copy_from
string
File on the host. Its bytes are the content. Its permission bits, without the write bits of the group and others, are the default mode. The default owner and group stay root: the owner of the source does not carry over.
file.stock
boolean, default false
Content that the package ships for path, from the installed version. The package also gives the default owner, group, and mode.
file.owner
name or ID, default root
A user name or a numeric ID. A step without content has no default.
file.group
name or ID, default root
A group name or a numeric ID. A step without content has no default.
file.mode
string, default 0644
Octal, in quotes: "0640". Without quotes, YAML reads it as a number. With stock, the package gives the default. With copy_from, the source gives it, without the write bits of the group and others. A step without content has no default.
file.validate
string
Check command for the new file. The command names the real path, or checks the whole config: nginx -t. winch puts the new file in place and runs the command. When the command fails, the old file comes back and the step fails.
file.absent
boolean, default false
Remove the file. A path of another kind fails the check.
file.replace
boolean, default false
Remove another kind of thing at path first, such as a directory. Without it, such a thing fails the check.
Example
- name: Write the message of the day
file:
path: /etc/motd
content: "Welcome to mail.example.com.\n"
mode: "0644"