Linux批量修改主机密码
Posted herlly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux批量修改主机密码相关的知识,希望对你有一定的参考价值。
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 效率
remote_user: root
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
运行
ansible-playbook change_passwd.yaml
3、根据IP条件去修改主机密码
vi change_passwd.yaml
- hosts: ssh
remote_user: root
tasks:
- name: change password
shell: echo item.password |passwd --stdin root
when: ansible_ens32.ipv4.address == item.ip
with_items:
- ip: "192.168.94.138", password: Asdf1234
- ip: "192.168.94.139", password: Asdf1234
运行
ansible-playbook change_passwd.yaml
以上是关于Linux批量修改主机密码的主要内容,如果未能解决你的问题,请参考以下文章