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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章