1.安裝ansible
yum -y install ansible
2.配置將客戶端信息加到ansible得hosts配置文件中
3.ansible服務端配置生成公鑰,執行以下命令然後一直回車即可。
ssh-keygen -t rsa
4.配置ansible劇本文件push-ssh.yml
- hosts: ssh_host
tasks:
- name: Transfer file from ServerA to ServerBC
copy:
src: /root/.ssh/id_rsa.pub
dest: /root/.ssh/
mode: 0600
- name: Rename client ssh file
command: mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
- name: change direction .ssh to 700
command: chmod 700 /root/.ssh