實例學習ansible系列(8)常用模塊之user/group
阿新 • • 發佈:2018-12-29
sys 人工智能 pretty http mov spa 添加用戶 老師 ups
知識點:user模塊,用於管理用戶。
知識點:group模塊,用於管理group。
使用user模塊添加用戶
[root@host31 ~]# ansible host32 -m command -a "id test01"
host32 | FAILED | rc=1 >>
id: test01: no such user
[root@host31 ~]# ansible host32 -m user -a "name=test01 group=root"
host32 | SUCCESS => {
"changed": true,
"comment" : "",
"createhome": true,
"group": 0,
"home": "/home/test01",
"name": "test01",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
[root@host31 ~]# ansible host32 -m command -a "id test01"
host32 | SUCCESS | rc=0 >>
uid=1001(test01) gid=0(root) groups=0(root)
[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
使用user模塊刪除用戶
[root@host31 ~]# ansible host32 -m user -a "name=test01 state=absent remove=yes"
host32 | SUCCESS => {
"changed": true,
"force": false,
"name": "test01",
"remove": true,
"state": "absent"
}
[root@host31 ~]# ansible host32 -m command -a "id test01"
host32 | FAILED | rc=1 >>
id: test01: no such user
[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
使用group 模塊添加group
[root@host31 ~]# ansible host32 -m shell -a "cat /etc/group |grep testgrp01"
host32 | FAILED | rc=1 >>
[root@host31 ~]# ansible host32 -m group -a "name=testgrp01"
host32 | SUCCESS => {
"changed": true,
"gid": 1001,
"name": "testgrp01",
"state": "present",
"system": false
}
[root@host31 ~]# ansible host32 -m shell -a "cat /etc/group |grep testgrp01"
host32 | SUCCESS | rc=0 >>
testgrp01:x:1001:
[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
使用group模塊刪除group
[root@host31 ~]# ansible host32 -m group -a "name=testgrp01 state=absent"
host32 | SUCCESS => {
"changed": true,
"name": "testgrp01",
"state": "absent"
}
[root@host31 ~]# ansible host32 -m shell -a "cat /etc/group |grep testgrp01"
host32 | FAILED | rc=1 >>
[root@host31 ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!https://www.cnblogs.com/captainbed
實例學習ansible系列(8)常用模塊之user/group