介绍两种法批量修改用户密码
方法一:
1、这个方法适用于更改多个固定的用户;playbook写法如下:
# cat play.yml
---
- hosts: test
gather_facts: false
tasks:
- name: change user passwd
user: name={{ item.name }} password={{ item.chpass | password_hash(‘sha512‘) }} update_password=always
with_items:
- { name: ‘root‘, chpass: ‘admin#123‘ }
- { name: ‘test‘, chpass: ‘[email protected]‘ }
1.1、执行playbook:
# ansible-playbook play.yml
方法二:
2、这个方法更改单用户比较方便;playbook写法如下:
cat play.yml
---
- hosts: test
gather_facts: false
tasks:
- name: Change password
user: name={{ name1 }} password={{ chpass | password_hash(‘sha512‘) }} update_password=always
2 .1、执行,test为用户名,admin#123就是要设置密码
#ansible-playbook play1.yml -e "name1=test chpass=admin#123"
原文地址:http://blog.51cto.com/75368/2140404
时间: 2024-11-16 03:52:08