实例学习ansible系列(6)常用模块之file,ansiblefile


知识点:使用ansible可以用来设置文件属性。熟悉脚本的人可能直接会在command或者shell模块中设定可能会更加快捷。不过这样写,一定程度上读起来一致性更好一点。

file的常用Option

Option 说明
path 设定对象文件/目录
owner 设定文件/目录的Owne
group 设定文件/目录的Group
mode 设定文件/目录的权限

file的使用实例

设定对象机器的某一文件的Owner/Group/mode

[root@host31 ~]# ansible host32 -m command -a "ls -l /tmp/hello.sh"
host32 | SUCCESS | rc=0 >>
-rwxr-x---. 1 root root 31 Jul 30 05:59 /tmp/hello.sh

[root@host31 ~]# ansible host32 -m file -a "path=/tmp/hello.sh owner=admin group=admin mode=0777"
host32 | SUCCESS => {
    "changed": true,
    "gid": 1000,
    "group": "admin",
    "mode": "0777",
    "owner": "admin",
    "path": "/tmp/hello.sh",
    "secontext": "unconfined_u:object_r:admin_home_t:s0",
    "size": 31,
    "state": "file",
    "uid": 1000
}
[root@host31 ~]# ansible host32 -m command -a "ls -l /tmp/hello.sh"
host32 | SUCCESS | rc=0 >>
-rwxrwxrwx. 1 admin admin 31 Jul 30 05:59 /tmp/hello.sh

[root@host31 ~]#

相关内容

    暂无相关文章