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

目录
相关文章
|
8月前
|
运维 Shell Linux
Ansible自动化运维工具之常用模块使用实战(5)
Ansible自动化运维工具之常用模块使用实战(5)
|
10月前
|
网络协议 网络安全
Ansible模块介绍——防火墙模块
Ansible模块介绍——防火墙模块
165 0
|
18天前
|
算法 安全 Linux
Ansible 中的copy 复制模块应用详解
Ansible 中的copy 复制模块应用详解
|
8月前
|
运维 Linux
Ansible自动化运维工具之常用模块使用实战(6)
Ansible自动化运维工具之常用模块使用实战(6)
|
11月前
|
Shell
ansible模块大全上【建议收藏】
ansible模块大全上【建议收藏】
108 0
ansible模块大全上【建议收藏】
|
7月前
|
网络安全 数据安全/隐私保护
ansible的get_url模块
ansible的get_url模块
|
7月前
|
存储 Linux Python
ansible手动添加模块
ansible手动添加模块
56 0
|
10月前
Ansible模块管理——磁盘管理模块、mount模块
Ansible模块管理——磁盘管理模块、mount模块
281 0
|
10月前
|
网络协议 网络安全 数据安全/隐私保护
Ansible模块介绍——配置网络模块、上传下载文件模块
Ansible模块介绍——配置网络模块、上传下载文件模块
287 0
|
10月前
|
应用服务中间件 nginx
Ansible模块——软件包管理模块
Ansible模块——软件包管理模块