首页 > 其他 > 详细

ansible批量修改root为随机密码

时间:2018-07-31 15:08:44      阅读:260      评论:0      收藏:0      [点我收藏+]
直接利用ansible-playbook实现,首先能免密登陆每个节点,可以执行ansible all -m ping测试,然后执行下面playbook。

[root@localhost ansible]# vim passwd.yaml

- hosts: test
remote_user: root
tasks:
- name: Generate the password
shell: openssl rand -base64 12 | cut -b 1-8  > ~/.openssl
- name: modify passwd
shell: echo `cat ~/.openssl` | passwd --stdin root
- name: fetch file
fetch:
src: ~/.openssl
dest: ~/fetch/openssl-{{ inventory_hostname }}
flat: yes
- name: delete pass file
shell: rm -rf ~/.openssl
- hosts: ‘{{hosts}}‘
remote_user: root
tasks:
- name:
shell: for i in `ls ~/fetch`;do echo -e ${i##openssl-}\|`cat ~/fetch/$i` >> ~/fetch/.`date +%F-%R`_passwd;done

2、执行

[root@localhost ansible]# ansible-playbook passwd.yaml -e "hosts=192.168.0.50"
#hosts为你ansible-server端地址

3、查看修改的密码

[root@localhost ansible]# cat ~/fetch/.2018-07-31-13\:47_passwd

192.168.0.37|S2oeLoaa
192.168.0.50|zPaV75Tt

ansible批量修改root为随机密码

原文:http://blog.51cto.com/13762620/2152569

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!