Write your own playbook batch modify the password and the public key push to achieve free dense login!
Enterprise
2019-06-24 04:19:16
views: null
Write your own playbook batch modify the password and the public key push to achieve free dense login!
Due to the need the need to write this thing, put this record down.
The first step: using ssh-keygen -t rsa generate the key pair.
Step two: add ansible hosts, this is my test instead.
Step 3: Define the server sshd_config documents in the root login privileges is turned on.
Example code:
- hosts: test
sudo: yes
tasks:
- name: 修改sshd_config文件
shell: sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
notify: restart sshd
- name: change the root password
shell: echo 'password' | passwd --stdin root
- name: 分发公钥
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
state: present
exclusive: no
handlers:
- name: restart sshd
shell: service sshd restart
Origin blog.51cto.com/11801990/2412450