zoukankan      html  css  js  c++  java
  • [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

  • 相关阅读:
    第5-7次OO作业总结分析
    面向对象课程作业1-3总结分析
    OO第四次作业总结
    OO第三次作业总结
    OO第二次作业总结
    OO第一次作业总结
    BUAA 编译源码阅读_pascal
    OO第四阶段总结
    OO第三阶段总结
    OO第二阶段总结
  • 原文地址:https://www.cnblogs.com/leoshi/p/13667475.html
Copyright © 2011-2022 走看看