ansible.windows.win_file 模块 – 创建、触摸或删除文件或目录

注意

此模块是 ansible.windows 集合 (版本 2.5.0) 的一部分。

如果您正在使用 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install ansible.windows

要在 playbook 中使用它,请指定:ansible.windows.win_file

概要

  • 创建(空)文件,更新现有文件的文件修改时间戳,并可以创建或删除目录。

  • ansible.builtin.file 不同,它不会修改所有权、权限或操作链接。

  • 对于非 Windows 目标,请改用 ansible.builtin.file 模块。

参数

参数

注释

path

别名:dest, name

path / 必需

要管理的文件的路径。

state

string

如果为 directory,则如果不存在,将创建所有直接子目录。

如果为 file,则如果文件不存在,将不会创建该文件,如果您想要这种行为,请参阅 ansible.windows.win_copyansible.windows.win_template 模块。

如果为 absent,则将递归删除目录,并删除文件。

如果为 touch,如果 path 不存在,则将创建一个空文件,而现有文件或目录将接收更新的文件访问和修改时间(类似于 touch 从命令行工作的方式)。

选择

  • "absent"

  • "directory"

  • "file"

  • "touch"

参见

另请参阅

ansible.builtin.file

管理文件和文件属性。

ansible.windows.win_acl

为系统用户或组设置文件/目录/注册表/证书权限。

ansible.windows.win_acl_inheritance

更改 ACL 继承。

ansible.windows.win_owner

设置所有者。

ansible.windows.win_stat

获取有关 Windows 文件的信息。

示例

- 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

作者

  • Jon Hawkesworth (@jhawkesworth)