module – Creates, touches or removes files or directories


This module is part of the collection (version 2.4.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install

To use it in a playbook, specify:


  • Creates (empty) files, updates file modification stamps of existing files, and can create or remove directories.

  • Unlike ansible.builtin.file, does not modify ownership, permissions or manipulate links.

  • For non-Windows targets, use the ansible.builtin.file module instead.





aliases: dest, name

path / required

Path to the file being managed.



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 or module if you want that behavior.

If absent, directories will be recursively deleted, and files will be removed.

If touch, an empty file will be created if the path does not exist, while an existing file or directory will receive updated file access and modification times (similar to the way touch works from the command line).


  • "absent"

  • "directory"

  • "file"

  • "touch"

See Also

See also


Manage files and file properties.

Set file/directory/registry/certificate permissions for a system user or group.

Change ACL inheritance.

Set owner.

Get information about Windows files.


- name: Touch a file (creates if not present, updates modification time if present)
    path: C:\Temp\foo.conf
    state: touch

- name: Remove a file, if present
    path: C:\Temp\foo.conf
    state: absent

- name: Create directory structure
    path: C:\Temp\folder\subfolder
    state: directory

- name: Remove directory structure
    path: C:\Temp
    state: absent


  • Jon Hawkesworth (@jhawkesworth)