1、控制机上执行:ssh-keygen
2、一路回车
3、vi rsync_key.yml
-
hosts: all
gather_facts: false
tasks:
-
name: copy ssh key
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
4、ansible-playbook rsync_key.yml
-
PS:ansible的hosts文件必须是一开始已经设置好