一、两种法批量增加用户和设置密码

1、第一种

 1.1 playbook

---
- hosts: "`hosts`"
  gather_facts: false

  tasks:
  - name: Change password
    user: name={{ item }} password={{ new_pass | password_hash('sha512') }}
    with_items: users

 1.2 执行,214就是要设置密码

ansible-playbook testuser.yml -e "hosts=jump users=testuser new_pass=*(214)"


2、第二种

 2.1 playbook

---
  - hosts: all
    user: root
    vars:
        # created with:
        #     # python -c 'python -c 'import crypt; print crypt.crypt("hh4213", "hadoop")'
        password: haHAfV7dvUhpM
    tasks:
        - user: name=hruser password=`password` update_password=always

 2.2 调用crypt 模块

    (只用于 Unix)实现了单向的 DES 加密, Unix 系统使用这个加密算法来储存密码。

[root@hrserver1 user]# python -c 'import crypt; print crypt.crypt("hh4213", "hadoop")'
haHAfV7dvUhpM

 2.3 得到加密算法密码haHAfV7dvUhpM代入剧本password

 2.4 执行

       ansible-playbook  user_pass.yml -v