ansible模块--user模块

常见的用户操作:
useradd 用户名 # 创建普通用户
passwd 用户名 # 设置用户密码
useradd -M -s /sbin/nologin 用户名 # 创建的用户没有家目录,不能登录
useradd -u 用户id -g gid 用户名 # 创建用户时指定uid和gid
userdel -r 用户 # 连同用户家目录一起删除用户

https://www.cndba.cn/hbhe0316/article/17022
https://www.cndba.cn/hbhe0316/article/17022
https://www.cndba.cn/hbhe0316/article/17022 https://www.cndba.cn/hbhe0316/article/17022
https://www.cndba.cn/hbhe0316/article/17022
https://www.cndba.cn/hbhe0316/article/17022

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:指定用户的附加组https://www.cndba.cn/hbhe0316/article/17022https://www.cndba.cn/hbhe0316/article/17022

[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 删除用户

https://www.cndba.cn/hbhe0316/article/17022
https://www.cndba.cn/hbhe0316/article/17022
[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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值