ansible模块--user模块
ansible模块--user模块
常见的用户操作:useradd 用户名 # 创建普通用户passwd 用户名 # 设置用户密码useradd -M -s /sbin/nologin 用户名 # 创建的用户没有家目录,不能登录useradd -u 用户id -g gid 用户名 # 创建用户时指定uid和giduserdel -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:指定用户的uidgroups:指定用户的附加组
[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
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~