Ansible配置免密登陸


<!--

0x01:  把遠程服務器的公鑰來獲取到本地

  1. #ssh-keyscan ip1 ip2 ip3 ip4 >> /root/.ssh/known_hosts

  完成后,/root/.ssh/known_hosts 多了許多內容

0x02: 添加服務IP到 ansible 的 hosts

  1. #cat >> /etc/ansible/hosts << EOF
  2. ip1
  3. ip2
  4. ip3
  5. ip4
  6. EOF
  7. #

0x03: 添加免密登錄(我的ROOT密碼都一樣,使用 -k 參數, 然后輸入 root 密碼)

  1. ansible all -m authorized_key -a "user=root state=present key=\"{{ lookup('file', '/root/.ssh/id_rsa.pub') }} \""-k

0x04: 驗證免密登陸

  1. #ansible all -m ping
  2. 172.16.13.5| SUCCESS =>{
  3. "changed":false,
  4. "failed":false,
  5. "ping":"pong"
  6. }
  7. 172.16.13.15| SUCCESS =>{
  8. "changed":false,
  9. "failed":false,
  10. "ping":"pong"
  11. }
  12. 172.16.13.6| SUCCESS =>{
  13. "changed":false,
  14. "failed":false,
  15. "ping":"pong"
  16. }
  17. 172.16.13.8| SUCCESS =>{
  18. "changed":false,
  19. "failed":false,
  20. "ping":"pong"
  21. }
  22. 172.16.13.9| SUCCESS =>{
  23. "changed":false,
  24. "failed":false,
  25. "ping":"pong"
  26. }
  27. #

  

  

<!--


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM