1、配置hosts
vi /etc/ansible/hosts
[ssh]
192.168.94.1[38:39]
[ssh:vars]
ansible_ssh_pass='Asdf1234'
2、编写playbook
vi change_passwd.yaml
- hosts: ssh
gather_facts: false #省去 facts 采集这一步以提高 playbook 效率
tasks:
- name: change user passwd
user: name={{ item.name }} password={{ item.passwd | password_hash('sha512') }} update_password=always
with_items:
- { name: 'root', passwd: 'Asdf1234' }
- { name: 'dev', passwd: 'Asdf1234' }