实现批量修改目标主机多个用户密码:
---
- hosts: testchanange passwd
gather_facts: false
tasks:
- name: change you passwd
user: name={{ item.name }} password={{ item.chpass | password_hash('sha512') }} update_password=always
with_items:
- { name: 'admin', chpass: 'h3&azym39mGcW' }
- { name: 'testuser', chpass: 'abcqwe1234'}
以非root用户连接目标主机通过 sudo执行 剧本:
ansible-playbook play.yml --user=app --private-key=/home/app/.ssh/id_rsa -b
解析:-b 是 become -s 是旧版本的sudo