当前位置: 首页 > news >正文

Ansible学习笔记7

user模块:

user模块用于管理用户账户和用户属性。

如果是windows要换一个win_user模块。

创建用户:present:

[root@localhost ~]# ansible group1 -m user -a "name=aaa state=present"
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"comment": "","create_home": true,"group": 1000,"home": "/home/aaa","name": "aaa","shell": "/bin/bash","state": "present","system": false,"uid": 1000
}
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"comment": "","create_home": true,"group": 1000,"home": "/home/aaa","name": "aaa","shell": "/bin/bash","state": "present","system": false,"uid": 1000
}
[root@agent1 tmp]# id aaa
uid=1000(aaa) gid=1000(aaa) groups=1000(aaa)[root@agent2 ~]# id aaa
uid=1000(aaa) gid=1000(aaa) groups=1000(aaa)

更改用户uid::这些内容都是Linux基础。

[root@localhost ~]# ansible group1 -m user -a "name=aaa uid=2000"
192.168.17.106 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": false,"comment": "","group": 1000,"home": "/home/aaa","move_home": false,"name": "aaa","shell": "/bin/bash","state": "present","uid": 2000
}
192.168.17.105 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": false,"comment": "","group": 1000,"home": "/home/aaa","move_home": false,"name": "aaa","shell": "/bin/bash","state": "present","uid": 2000
}

更改用户的属性:那这块还需要自己再进一步的分析:

[root@localhost ~]# ansible group1 -m user -a "name=aaa home=/data/haha shell=/bin/false comment=@_@"
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": true,"comment": "@_@","group": 1000,"home": "/data/haha","move_home": false,"name": "aaa","shell": "/bin/false","state": "present","uid": 2000
}
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": true,"comment": "@_@","group": 1000,"home": "/data/haha","move_home": false,"name": "aaa","shell": "/bin/false","state": "present","uid": 2000
}

然后到agent机器上检查:

[root@agent1 tmp]# cat /etc/passwd |grep aaa
aaa:x:2000:1000:@_@:/data/haha:/bin/false

删除用户:

[root@localhost ~]# ansible group1 -m user -a "name=aaa state=absent"                              192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"force": false,"name": "aaa","remove": false,"state": "absent"
}
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"force": false,"name": "aaa","remove": false,"state": "absent"
}

然后再到agent的机器上检查,可见用户已删除:

[root@agent1 tmp]# id aaa
id: aaa: no such user
[root@agent1 tmp]# grep aaa /etc/passwd
[root@agent1 tmp]#

删除用户的时候需要注意删除家目录的问题:

删除家目录的场景:

[root@localhost ~]# ansible group1 -m user -a "name=bbb state=absent remove=yes"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"force": false,"name": "bbb","remove": true,"state": "absent"
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"force": false,"name": "bbb","remove": true,"state": "absent"
}
[root@agent1 tmp]# cd /home/bbb
-bash: cd: /home/bbb: No such file or directory

 

 

这两个,如果工作中需要可以试下。

http://www.lryc.cn/news/150950.html

相关文章:

  • Python3 对列表、字典以及二者的嵌套数据(JSON)格式排序
  • 如何在B站进行学习直播
  • 老卫带你学---windows上安装minikube
  • Neo-reGeorg隧道搭建
  • Elasticsearch 7.6 - API高阶操作篇
  • 软件第三方验收测评介绍
  • HarmonyOS—使用Web组件加载页面
  • Redis 缓存穿透、击穿、雪崩
  • 设计模式-原型模式详解
  • 大语言模型之七- Llama-2单GPU微调SFT
  • 房地产行业专题报告:日本房地产市场借鉴
  • Educational Codeforces Round 154 (Rated for Div. 2)
  • elasticsearch批量删除(查询删除)
  • 容器技术Linux Namespaces和Cgroups
  • GO语言圣经 第四章习题
  • 远程连接Ubuntu 22.04
  • 字节前端实习的两道算法题,看看强度如何
  • 设计模式—策略模式
  • LPDDR4、DDR4
  • ESP32C3 LuatOS RC522①写入数据并读取M1卡
  • MusicBrainz Picard for Mac :音乐文件ID3编辑器
  • ❤ Uniapp使用
  • 解密Spring事务生效的内部机制
  • 大数据时代下的数据安全防护
  • RabbitMQ-常用命令
  • Spring中依赖注入的继承bean的细节问题
  • 海外腾讯云服务器手机上无法访问外网怎么办??
  • python3+requests:接口自动化测试(二)
  • uni-app:允许字符间能自动换行(英文字符、数字等)
  • day 42 |● 121. 买卖股票的最佳时机 ● 122.买卖股票的最佳时机II