主页 > 软件开发  > 

ansible批量修改主机密码


在修改密码之前呢,请先明白一件事情 password 字段需要使用加密的密码,而不是明文密码 如果直接用剧本批量写入密码,会因为 密码哈希算法不匹配 导致登陆不成功

可以使用 Python 的 passlib 库来生成 SHA-512 加密的密码。(根据使用的python版本调整命令,这里默认使用python3)

1、首先,你需要安装 passlib 库。你可以使用 pip3 命令来安装:

yum -y install python3 pip3 install passlib

2、使用python脚本来生成加密的密码

from passlib.hash import sha512_crypt password = sha512_crypt.hash("your_password") print(password)

3、编写playbook 剧本

--- - name: Change root password hosts: all #主机组 become: yes #是否使用root用户 tasks: - name: Change root password user: name: root password: "$6$rounds=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" update_password: always

4、执行剧本

playbook xxx.yaml
标签:

ansible批量修改主机密码由讯客互联软件开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“ansible批量修改主机密码