使用ansible批量修改ubuntu系统密码

1.在对应的ubuntu服务器上传ansible服务器的公钥,确保能够无密登录 2.编写密码设置脚本 #vim pw.sh #!/bin/bash echo "root:/bP1QR9%?JC/qkBa"|chpasswd 3.编写ansible的hosts文件,添加ubuntu服务器列表(132.152-132.235) #vim /etc/ansible/hosts [ubuntu-servers] 192.168.132.[152:235]:22

4.编写ansible playbook

  • hosts: ubuntu-servers remote_user: root tasks:
    • name: transfer file to server copy: src=/root/nht/pw.sh dest=/tmp/pswd.sh mode=755
    • name: zhixing become: yes shell: /bin/bash -x /tmp/pswd.sh 5.执行剧本 #ansible-playbook main.yaml 收工