ansible模块--user模块
原创
©著作权归作者所有:来自51CTO博客作者wx62e28ac222a20的原创作品,请联系作者获取转载授权,否则将追究法律责任
常见的用户操作:
useradd 用户名 # 创建普通用户
passwd 用户名 # 设置用户密码
useradd -M -s /sbin/nologin 用户名 # 创建的用户没有家目录,不能登录
useradd -u 用户id -g gid 用户名 # 创建用户时指定uid和gid
userdel -r 用户 # 连同用户家目录一起删除用户
1.创建user
[root@ansible ansible]# ansible -i hosts mysql -m user -a 'name=hbhe0316'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 1001,
"home": "/home/hbhe0316",
"name": "hbhe0316",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
2.添加附属条件
指定用户的uid号,附加组
append=yes #增量添加附加组
uid:指定用户的uid
groups:指定用户的附加组
[root@ansible ansible]# ansible -i hosts mysql -m user -a 'uid=5000 groups=hbhe0316 name=hbhe0317'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"comment": "",
"create_home": true,
"group": 5000,
"groups": "hbhe0316",
"home": "/home/hbhe0317",
"name": "hbhe0317",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 5000
}
3.删除用户
remove=yes 删除用户的同时删除家目录
state=absent 删除用户
[root@ansible ansible]# ansible -i hosts mysql -m user -a 'name=hbhe0317 state=absent remove=yes'
192.168.56.88 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"force": false,
"name": "hbhe0317",
"remove": true,
"state": "absent"
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
ansible