1. 将服务器ip写到ansible hosts文件中 2. 实现免密登录服务器 将ansible服务器公钥拷贝到目标服务器用户目录下的.ssh/authorized_keys 手动连接一次或者自己写脚本
3. 编写playbook 批量修改多用户密码 - 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: '123456' } - { name: 'liutao', chpass: 'Mlxg2234' }
4. 修改单个用户 - hosts: test gather_facts: false tasks: - name: Change password user: name={{ name1 }} password={{ chpass | password_hash('sha512') }} update_password=always
ansible-playbook play.yml -e "name1=root chpass=123456"