W3cubDocs

/Ansible

win_file - Creates, touches or removes files or directories.

New in version 1.9.2.

Synopsis

  • 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.

Options

parameter required default choices comments
path
yes
path to the file being managed. Aliases: dest, name
aliases: dest, name
state
no
  • file
  • directory
  • touch
  • absent
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).

Examples

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

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

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

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

Notes

Note

Status

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

Maintenance Info

For more information about Red Hat’s this support of this module, please refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.

© 2012–2017 Michael DeHaan
© 2017 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/win_file_module.html