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