Skip to main content

file

file module

Manage files, directories, and symbolic links. This module can create, remove, or modify the state and permissions of filesystem objects.

Examples

- name: Create a file
file:
path: /tmp/myfile.txt
state: touch
mode: '0644'

- name: Create a directory
file:
path: /opt/myapp
state: directory
mode: '0755'

- name: Create a symbolic link
file:
src: /etc/myapp/config.conf
path: /tmp/config.link
state: link

- name: Remove a file or directory
file:
path: /tmp/unwanted
state: absent

Note: The 'touch' and 'file' states are equivalent and will create an empty file if it doesn't exist.

Module Capabilities

  • Has Revert: true
  • Provides Variables: None

Inputs

ParameterTypeDescriptionRequiredDefaultChoices
modestringFile permissions to set (e.g., '0644', '0755'). Not applicable to links.false
pathstringPath to the file, directory, or link to manage.true
srcstringSource path for symbolic links. Only used when state=link.false
statestringDesired state of the filesystem object.falsefilefile, touch, directory, link, absent

Outputs

No outputs.

Parameter aliases

  • dest → path
  • name → path