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 模块。
参数
参数 |
注释 |
---|---|
要管理的文件的路径。 |
|
如果为 如果为 如果为 如果为 选择
|
参见
另请参阅
- 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