码迷,mamicode.com
首页 > 其他好文 > 详细

ansible 之file模块

时间:2018-03-05 11:09:31      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ansible 之file模块

调用-s 参数,需要客户端能够无密码使用sudo 命令;
例:更改所有节点上/tmp/test.sh 的权限为755,属主和属组为root

[root@master ~]# ansible slave -m file -a "dest=/tmp/test.sh mode=755 owner=root group=root" –s

[root@master ~]# ansible slave -m file -a "dest=/tmp/test.sh mode=755 owner=root group=root" -s
10.0.0.20 | SUCCESS => {
    "changed": false, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/tmp/test.sh", 
    "size": 76, 
    "state": "file", 
    "uid": 0
}
10.0.0.21 | SUCCESS => {
    "changed": false, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/tmp/test.sh", 
    "size": 76, 
    "state": "file", 
    "uid": 0
}

调用-s 参数,需要客户端能够无密码使用sudo 命令;
例:更改所有节点上/tmp/test0001 的权限为644,属主和属组为boy
前提是client节点必须已经创建用户boy

[root@client01 tmp]# useradd boy
[root@client02 tmp]# useradd boy

[root@master ~]# ansible slave -m file -a "dest=/tmp/txt01 mode=755 owner=boy group=boy" -s
client02 | SUCCESS => {
    "changed": true, 
    "gid": 500, 
    "group": "boy", 
    "mode": "0755", 
    "owner": "boy", 
    "path": "/tmp/txt01", 
    "size": 6, 
    "state": "file", 
    "uid": 500
}
agent.test.com | SUCCESS => {
    "changed": true, 
    "gid": 501, 
    "group": "boy", 
    "mode": "0755", 
    "owner": "boy", 
    "path": "/tmp/txt01", 
    "size": 6, 
    "state": "file", 
    "uid": 501
}

否则报错:
[root@master ~]# ansible slave -m file -a "dest=/tmp/txt01 mode=755 owner=boy group=boy" -s
agent.test.com | FAILED! => {
    "changed": false, 
    "failed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0644", 
    "msg": "chown failed: failed to look up user boy", 
    "owner": "root", 
    "path": "/tmp/txt01", 
    "size": 6, 
    "state": "file", 
    "uid": 0
}
client02 | FAILED! => {
    "changed": false, 
    "failed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0644", 
    "msg": "chown failed: failed to look up user boy", 
    "owner": "root", 
    "path": "/tmp/txt01", 
    "size": 6, 
    "state": "file", 
    "uid": 0
}

[root@client01 tmp]# ll txt01 
-rwxr-xr-x 1 boy boy 6 Jul 30 20:50 txt01

[root@client02 tmp]# ll txt01 
-rwxr-xr-x 1 boy boy 6 Jul 30 20:50 txt01

ansible 之file模块

标签:ansible 之file模块

原文地址:http://blog.51cto.com/wujianwei/2082891

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!