自动化运维、大数据、Docker

实例学习ansible系列(8)常用模块之user/group

知识点: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 ~]#

使用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 ~]#

使用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 ~]#

使用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 ~]#

本文转载自 实例学习ansible系列(8)常用模块之user/group

赞(0) 打赏
蜷缩的蜗牛 , 版权所有丨如未注明 , 均为原创丨 转载请注明蜷缩的蜗牛 » 实例学习ansible系列(8)常用模块之user/group
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏