[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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM