ansible--user和group模块用户创建及删除

简介: 执行脚本增加用户[root@10-15-195-231 roles]#ansible test -a "/root/addappuser.sh ansible"addappuser.sh 为远端服务器上的脚本[root@10-15-195-231 ~]# cat addappuser.

执行脚本增加用户
[root@10-15-195-231 roles]#ansible test -a "/root/addappuser.sh ansible"
addappuser.sh 为远端服务器上的脚本
[root@10-15-195-231 ~]# cat addappuser.sh

!/bin/bash

username=$1
useradd -G app -d /data/$username -s /bin/bash $username
echo "$username" |passwd --stdin $username
echo "$username" >> /etc/sshusers

group模块
[root@10-15-190-167 roles]# ansible test -m group -a "gid=2016 name=app1"
10.15.195.231 | SUCCESS => {

"changed": true, 
"gid": 2016, 
"name": "app1", 
"state": "present", 
"system": false

}
10.15.66.32 | SUCCESS => {

"changed": true, 
"gid": 2016, 
"name": "app1", 
"state": "present", 
"system": false

}
user模块
使用user模块增加、删除用户
删除用户
[root@10-15-195-231 ~]# ansible test -m user -a "name=test state=absent"
10.15.66.32 | SUCCESS => {

"changed": true, 
"force": false, 
"name": "test", 
"remove": false, 
"state": "absent"

}
增加用户
[root@10-15-195-231 ~]# ansible test -m user -a "name=test state=present"
10.15.66.32 | SUCCESS => {

"changed": true, 
"comment": "", 
"createhome": true, 
"group": 1003, 
"home": "/home/test", 
"name": "test", 
"shell": "/bin/bash", 
"state": "present", 
"stderr": "Creating mailbox file: File exists\n", 
"system": false, 
"uid": 1002

}
增加用户指定用户组,但在目标机器的/etc/group的APP1组中找不到新增的用户,在/etc/passwd中可以看到用户组,组权限对应文件夹亦生效
[root@10-15-190-167 roles]# ansible test -m user -a "name=test12 group=app1 state=present"
10.15.195.231 | SUCCESS => {

"changed": true, 
"comment": "", 
"createhome": true, 
"group": 2016, 
"home": "/home/test12", 
"name": "test12", 
"shell": "/bin/bash", 
"state": "present", 
"system": false, 
"uid": 1001

}
10.15.66.32 | SUCCESS => {

"changed": true, 
"comment": "", 
"createhome": true, 
"group": 2016, 
"home": "/home/test12", 
"name": "test12", 
"shell": "/bin/bash", 
"state": "present", 
"system": false, 
"uid": 1003

}
测试组权限是否生效
[root@10-15-195-231 itms]# su - test12
Last login: Wed Nov 23 10:55:52 CST 2016 on pts/0
[test12@10-15-195-231 ~]$ ll
total 4
drwxrwx--- 21 root app1 4096 Aug 22 13:09 itms
可进入目录,已生效
test12@10-15-195-231 ~]$ cd itms/
[test12@10-15-195-231 itms]$ ls
ad baksource etc lib nullAPOS A8 tools
apache-tomcat-7.0.69 bin file log poi
app config jdk1.7.0_80 login_logo.png sodir

目录
相关文章
linux中的usermod 修改用户、groupadd 新增组、groupdel 删除组、groupmod 修改组、cat /etc/group 查看创建了哪些组llinux中的userdel 删除用户、who 查看登录用户信息、sudo 设置普通用户具有 root 权限
linux中的usermod 修改用户、groupadd 新增组、groupdel 删除组、groupmod 修改组、cat /etc/group 查看创建了哪些组llinux中的userdel 删除用户、who 查看登录用户信息、sudo 设置普通用户具有 root 权限
linux中的usermod 修改用户、groupadd 新增组、groupdel 删除组、groupmod 修改组、cat /etc/group 查看创建了哪些组llinux中的userdel 删除用户、who 查看登录用户信息、sudo 设置普通用户具有 root 权限
|
Linux 数据安全/隐私保护
LXJ
|
Unix Shell Linux
17-user模块-Ansible常用模块
17-user模块-Ansible常用模块
LXJ
152 1
LXJ
18-group模块-Ansible常用模块
18-group模块-Ansible常用模块
LXJ
106 0
|
Shell 数据安全/隐私保护
Ansible用户模块user和组模块group(学习笔记七)
user:生成用户、删除用户 group:生成组、删除组 1、生成用户:ansible all -m user -a "name=test password=1DhUWqz2JZqc home=/home uid=999 comment=‘this i...
1082 0