要想實現ansible控制主機免密登錄到其他遠程主機,則需要將ansible控制主機的主機密鑰分發到其他遠程主機上。
說明:ansible控制節點和被控制節點的系統版本如下,爲什麼要說明系統版本時因爲linux系統版本不同通過命令獲取的結果有可能不正確,可以根據自己實際系統版本進行調整。
[root@myhost yml]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@myhost yml]# cat step00_sshKeyBossToOthers.yml
---
- hosts: new #這個是hosts定義個主機組名字,如果是單臺主機可以直接寫地址,多個ip地址用都好隔開
gather_facts: no
tasks:
- name: give the pub_keys of the boss_host to the remote hosts to let the boss_host can login the remote hosts without password.
authorized_key:
user: root
key: "{{lookup('file','/root/.ssh/id_rsa.pub')}}"
state: present