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

  • 相关阅读:
    Python 特殊语法:filter、map、reduce、lambda
    db2 常用命令(二)
    db2 常用命令(一)
    java 基础
    No.16 selenium学习之路之异常处理
    python之assert断言
    python之uinttest单元测试框架
    测试用例
    No.15 selenium for python JavaScript
    No.14 selenium for python table表单
  • 原文地址:https://www.cnblogs.com/leoshi/p/13667475.html
Copyright © 2011-2022 走看看