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
Parameter | Type | Description | Required | Default | Choices |
---|---|---|---|---|---|
mode | string | File permissions to set (e.g., '0644', '0755'). Not applicable to links. | false | ||
path | string | Path to the file, directory, or link to manage. | true | ||
src | string | Source path for symbolic links. Only used when state=link. | false | ||
state | string | Desired state of the filesystem object. | false | file | file, touch, directory, link, absent |
Outputs
No outputs.
Parameter aliases
- dest → path
- name → path