1、添加用户属组
- name: add the new usergroup admin
group:
name: admin
state: present
2、添加用户,并加入创建好的属组,密码必须是加密后的密文,密文的生成建议使用python自带的模块passlib。
具体实现指令如下
python -c 'import crypt; print (crypt.crypt("redhat123","jhone"))'
ansible实现用户创建代码如下
- name: add the user jane with a bash shell,appending
user:
name: jane
shell: /bin/bash
password: jhGI.T8MoxCKA
update_password: always
groups: admins,developers
append: yes
3、删除用户及家目录
- name: remove the user robert
user:
name: robert
state: ab