批量添加用户
[[email protected] init]# cat useradds.sls
{% set users = [‘name1,name2‘] %}
{% for user in users %}
{{ user }}:
user.present:
- shell: /bin/bash
- home: /home/{{ user }}
- password: ‘$1$sbvWg7.V$r/nWDs7g0YynB1CVsfUPA/’
- groups:
- {{ user }}
- require:
- group: {{ user }}
group.present:
- name: {{ user }}
{% endfor %}
password为hash后的密码
获取hash后密文密码openssl passwd -1
[[email protected] init]# openssl passwd -1
Password:
Verifying – Password:
$1$bWsI2gYH$V.JqN/FE9J3yltwXCo.CQ/
批量删除用户
[[email protected] init]# cat userdel.sls
{% set users = [‘jerry‘,‘tom‘,‘sunday‘] %}
{% for user in users %}
{{ user }}:
user.absent:
- purge: True
- force: True
{% endfor %}
- purge: True ##Set purge to True to delete all of the user’s files as well as the user, Default is False.
- force: True ##如果用户当前已登录,则absent state会失败. 设置force选项为True时,就算用户当前处于登录状态也会删除本用户.