从网上找到批量修改Linux服务器root密码的playbook。

使用方法:

1、输入要修改的inventory组

2、按需要,在playbook中输入要修改的IP、新密码,如下:

 



- hosts: production
remote_user: root
tasks:
- name: change password for root
shell: echo '{{ item.password }}' |passwd --stdin root
when: ansible_eth0.ipv4.address == '{{ item.ip }}'
with_items:
- { ip: "ip1", password: 'password1' }
- { ip: "ip2", password: 'password2' }
- { ip: "ip3", password: 'password3' }


 

 

3、执行playbook

ansible-playbook change_passwd.yml