> For the complete documentation index, see [llms.txt](https://pshizhsysu.gitbook.io/ansible/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pshizhsysu.gitbook.io/ansible/ansiblemo-kuai/filemo-kuai.md).

# file模块

用于对文件进行操作

```
group：默认为空
owner：默认为空
path：默认为空，别名：'dest', `name'
recurse：yes, no 默认为no
src：创建连接文件时有用
```

```
state：file, link, directory, hard, touch, absent
file 默认属性，如果文件不存在则不创建，并且报错，用于修改已存在文件的属性
directory 如果目录不存在，则创建目录和子目录
absent 递归删除文件或目录
link 在创建软链接是有用
hard 创建硬链接
```

## 示例

```
- name: file module
  hosts: group1
  tasks:
  - name: delete a file
    file:
      path: /etc/yum.repos.d/peng.test
      state: absent
```
