/Ansible 2.9

win_file – Creates, touches or removes files or directories


  • Creates (empty) files, updates file modification stamps of existing files, and can create or remove directories.
  • Unlike file, does not modify ownership, permissions or manipulate links.
  • For non-Windows targets, use the file module instead.


Parameter Choices/Defaults Comments
path / required
Path to the file being managed.

aliases: dest, name
  • absent
  • directory
  • file
  • touch
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 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).

See Also

See also

file – Manage files and file properties
The official documentation on the file module.
win_acl – Set file/directory/registry permissions for a system user or group
The official documentation on the win_acl module.
win_acl_inheritance – Change ACL inheritance
The official documentation on the win_acl_inheritance module.
win_owner – Set owner
The official documentation on the win_owner module.
win_stat – Get information about Windows files
The official documentation on the win_stat module.


- 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


Red Hat Support

More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.


  • Jon Hawkesworth (@jhawkesworth)


If you notice any issues in this documentation, you can edit this document to improve it.

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.