.. _ansible.windows.win_file_module: ************************ ansible.windows.win_file ************************ **Creates, touches or removes files or directories** .. contents:: :local: :depth: 1 Synopsis -------- - Creates (empty) files, updates file modification stamps of existing files, and can create or remove directories. - Unlike :ref:`ansible.builtin.file `, does not modify ownership, permissions or manipulate links. - For non-Windows targets, use the :ref:`ansible.builtin.file ` module instead. Parameters ---------- .. raw:: html
Parameter Choices/Defaults Comments
path
path / required
Path to the file being managed.

aliases: dest, name
state
string
    Choices:
  • 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 ansible.windows.win_copy or ansible.windows.win_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 -------- .. seealso:: :ref:`ansible.builtin.file_module` The official documentation on the **ansible.builtin.file** module. :ref:`ansible.windows.win_acl_module` The official documentation on the **ansible.windows.win_acl** module. :ref:`ansible.windows.win_acl_inheritance_module` The official documentation on the **ansible.windows.win_acl_inheritance** module. :ref:`ansible.windows.win_owner_module` The official documentation on the **ansible.windows.win_owner** module. :ref:`ansible.windows.win_stat_module` The official documentation on the **ansible.windows.win_stat** module. Examples -------- .. code-block:: yaml - name: Touch a file (creates if not present, updates modification time if present) ansible.windows.win_file: path: C:\Temp\foo.conf state: touch - name: Remove a file, if present ansible.windows.win_file: path: C:\Temp\foo.conf state: absent - name: Create directory structure ansible.windows.win_file: path: C:\Temp\folder\subfolder state: directory - name: Remove directory structure ansible.windows.win_file: path: C:\Temp state: absent Status ------ Authors ~~~~~~~ - Jon Hawkesworth (@jhawkesworth)