签到成功

知道了

CNDBA社区CNDBA社区

ansible模块--user模块

2021-11-14 09:30 838 0 原创 ansible
作者: hbhe0316

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

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

1.创建user

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

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

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

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
hbhe0316

hbhe0316

关注

1.只有承认无知,才能装下新的东西; 2.进步来自一点点滴滴的积累; 3.广博让你更优秀,而专业让你无法替代; 4.挫折和失败能够转换为一种财富。

  • 889
    原创
  • 1
    翻译
  • 13
    转载
  • 24
    评论
  • 访问:1039276次
  • 积分:1523
  • 等级:核心会员
  • 排名:第6名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ