官網
- group 定義文件目錄的屬組
- mode 權限
- owner 屬主
- path 路徑
- recurse 遞歸目錄
- src link路徑
- dest 被鏈接到的路徑
- state
- absent 刪除
- directory 目錄不存在創建
- file 不創建文件檢查文件是否存在
- hard 硬鏈接
- link 軟鏈接
- touch 文件不存在創建,如果文件存在更新創建時間
# 創建文件
ansible webservers -m file -a "path=/tmp/foo.conf state=touch"
# 檢查文件
ansible webservers -m file -a "path=/tmp/foo.conf"
[root@ceph1 ~]# ansible webservers -m file -a "path=/tmp/foo.conf"
ceph3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"path": "/tmp/foo.conf",
"size": 0,
"state": "file",
"uid": 0
}
# 修改文件權限
ansible webservers -m file -a "path=/tmp/foo.conf owner=nobody group=nobody mode=0644"
# 創建link
ansible webservers -m file -a "src=/tmp/foo.conf dest=/tmp/link.conf state=link"
[root@ceph3 yum.repos.d]# ll /tmp/ | grep link
lrwxrwxrwx 1 root root 13 9月 14 16:21 link.conf -> /tmp/foo.conf
# 取消鏈接
ansible webservers -m file -a "src=/tmp/foo.conf dest=/tmp/link.conf state=absent"
# 創建一個目錄
ansible webservers -m file -a "path=/tmp/ansible state=directory"
# 刪除一個文件
ansible webservers -m file -a "path=/tmp/foo.conf state=absent"
END