使用ansible为所有节点设置免秘钥
hosts文件
需要在hosts文件中配置所有节点的ip,用户名,密码等信息
[node]
10.10.x.x ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=xxx
10.10.x.x ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=xxx
10.10.x.x ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=xxx
playbook文件
编辑playbook文件
---
- hosts: all
gather_facts: no
tasks:
- name: install sshkey
authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}" state=present
执行命令
执行命令为
ansible-playbook -i .hosts ssh-addkey.yml
使用过程中出现过个别节点无法正常配置免秘钥的情况,如果遇到需要使用 ssh-copy-id 手动配置