2.1 問題
本案例要求:
創建一對密鑰
cd /root/.ssh
ssh-keygen -t rsa -b 2048 -N '' -f key
給所有主機部署密鑰
ssh-copy-id -i key.pub 主機名稱
2.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:批量部署證書文件,給所有主機部署密鑰
1)創建密鑰
[root@ansible myansible]# cd /root/.ssh/
[root@ansible .ssh]# vim /etc/ansible/hosts
[web]
web1
web2
[db]
db[1:2]
[other]
cache
[root@ansible .ssh]# ansible all -m ping //直接ping會報錯
[root@ansible .ssh]# ssh-keygen -t rsa -b 2048 -N '' -f key //創建密鑰
2)給所有主機部署密鑰
[root@ansible .ssh]# ssh-copy-id -i key.pub 主機名稱
[root@ansible .ssh]# ansible all -m ping //失敗