ansible-playbook: 实现ansible控制主机免密登录到其他远程主机

要想实现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
      
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章