Ansible模块介绍——用户管理模块

简介: Ansible模块介绍——用户管理模块

用户管理模块

user模块

user模块实现用户账号管理

  • name:用户名
  • uid:用户uid
  • group:所属组,即私有组
  • groups:附加组
  • state:状态

示例

1.创建用户tom,密码为123 首先可以使用python的crypt命令来生成一个密码, 因为ansible user的password参数需要接受加密后的值

[root@master ~]#  python3  
Python 3.6.8  (default, Jan 11 2019, 02:17:16)  [GCC 8.2.1  20180905 (Red Hat 8.2.1-3)] on linux  Type  "help", "copyright", "credits" or  "license" for more information. 
\>>>  import crypt  
\>>>  crypt.crypt('123')  '$6$0Sv2s81pi/tqYlU.$AzguGYIz1fAbkKKm7AGi1I0XSCXS5670ZHjroKcQrdFQ8T7puWklzp41Zw4  DlFCuypVFfsv0PThfnYugI3Xr71'  
\>>>  exit()  
创建用户  
[root@master ~]#  ansible webservers -m user -a 'name=tom password="$6$0Sv2s81pi/tqYlU.$AzguGYIz1fAbkKKm7AGi1I0XSCXS5670ZHjroKcQrdFQ8T7puW  klzp41Zw4DlFCuypVFfsv0PThfnYugI3Xr71"'  
验证登录 
[root@master ~]#  ssh 192.168.150.22 -l tom  tom@192.168.150.22's  password: 
[tom@node2 ~]$  logout  Connection to  192.168.150.22 closed. 

2.删除用户,连同家目录一起

[root@master ~]#  ansible webservers -m user -a 'name=tom state=absent  remove=yes'  

3.创建用户bob,指定附加组为rhce

[root@master ~]#  ansible webservers -m user -a 'name=bob groups=rhce'  

4.为bob用户生成密钥对

[root@master ~]#  ansible webservers -m user -a 'name=bob generate_ssh_key=yes  ssh_key_bits=2048  ssh_key_file=.ssh/id_rsa' 
[root@master ~]#  ansible webservers -m shell -a 'ls -la ~bob/.ssh'  

group模块

group模块

  • name参数:必须参数,用于指定要操作的组名称。
  • state参数:用于指定组的状态,两个值可选,present,absent,默认为present,设置为absent 表示删除组。
  • gid参数:用于指定组的gid。
  • system参数:系统组。
    示例
    创建一个组rhce
[root@master  ~]# ansible webservers -m group -a 'name=rhce'


相关文章
|
12月前
|
运维 Shell Linux
Ansible自动化运维工具之常用模块使用实战(5)
Ansible自动化运维工具之常用模块使用实战(5)
279 0
|
网络协议 网络安全
Ansible模块介绍——防火墙模块
Ansible模块介绍——防火墙模块
237 0
|
2月前
|
缓存 Shell Linux
[ansible]常用内置模块
[ansible]常用内置模块
|
3月前
|
Shell 应用服务中间件 Linux
Ansible的常用模块
Ansible的常用模块
56 6
|
3月前
|
Shell 数据安全/隐私保护
Ansible Ad-hoc,命令执行模块
Ansible Ad-hoc,命令执行模块
31 1
|
3月前
|
运维 Linux 应用服务中间件
Linux之自动化运维工具ansible、ansible模块(2)
Linux之自动化运维工具ansible、ansible模块(2)
|
3月前
|
运维 Linux Shell
Linux之自动化运维工具ansible、ansible模块(1)
Linux之自动化运维工具ansible、ansible模块(1)
|
5月前
|
算法 安全 Linux
Ansible 中的copy 复制模块应用详解
Ansible 中的copy 复制模块应用详解
307 1
|
12月前
|
运维 Linux
Ansible自动化运维工具之常用模块使用实战(6)
Ansible自动化运维工具之常用模块使用实战(6)
177 0
|
11月前
|
网络安全 数据安全/隐私保护
ansible的get_url模块
ansible的get_url模块
121 1