.. _file: file `````````````````````````````` Sets attributes of files, symlinks, and directories, or removes files/symlinks/directories. Many other modules support the same options as the file module - including ``copy``, ``template``, and ``assmeble``. .. raw:: html
parameter | required | default | choices | comments |
---|---|---|---|---|
src | no | path of the file to link to (applies only to state=link ). |
||
group | no | name of the group that should own the file/directory, as would be fed to chown | ||
dest | yes | defines the file being managed, unless when used with state=link, and then sets the destination to create a symbolic link to using src | ||
selevel | no | s0 | level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range . _default feature works as for seuser. |
|
seuser | no | user part of SELinux file context. Will default to system policy, if applicable. If set to _default , it will use the user portion of the the policy if available |
||
state | no | file |
|
If directory , all immediate subdirectories will be created if they do not exist. If file , the file will NOT be created if it does not exist, see the copy or template module if you want that behavior. If link , the symbolic link will be created or changed. If absent , directories will be recursively deleted, and files or symlinks will be unlinked. |
serole | no | role part of SELinux file context, _default feature works as for seuser. |
||
mode | no | mode the file or directory should be, such as 0644 as would be fed to | ||
context | no |
|
accepts only default as value. This will restore a file's SELinux context in the policy. Does nothing if no default value is available. |
|
owner | no | name of the user that should own the file/directory, as would be fed to chown | ||
force | no | force is required when changing an existing file to a directory, or a link to a directory, and so on. Use this with caution. | ||
setype | no | type part of SELinux file context, _default feature works as for seuser. |
Example from Ansible Playbooks
file path=/etc/foo.conf owner=foo group=foo mode=0644
file src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
See also copy, template, assemble