[Ansible]file模块

官网

  • 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

posted @ 2020-09-14 16:25  LeoShi2020  阅读(1362)  评论(0编辑  收藏  举报