ansible 學習記錄(三) -- inventory 學習

  • VS Code 準備
node1 ansible_connection=ssh ansible_user=root ansible_ssh_pass=123456
  • VS Code 同步

Sync Local -> Remote

  • 服務器執行
[root@master ~]# ansible all -m ping -i /home/ansible-study/inventory/inventory.ini

在這裏插入圖片描述

  • inventory 編寫格式 && 使用
[root@master ~]# cat /home/ansible-study/inventory/inventory.ini 
[control]
master ansible_connection=ssh ansible_user=root ansible_ssh_pass=123456

[slave]
# node1 ansible_connection=ssh ansible_user=root ansible_ssh_pass=123456
# node2 ansible_connection=ssh ansible_user=root ansible_ssh_pass=123456
node[1:2] ansible_connection=ssh ansible_user=root ansible_ssh_pass=123456

在這裏插入圖片描述

[root@master ~]# ansible control -m ping -i /home/ansible-study/inventory/inventory.ini 		# 別名使用
[root@master ~]# ansible slave -m ping -i /home/ansible-study/inventory/inventory.ini 		# 別名使用

在這裏插入圖片描述

遇到問題問題

首次連接 known_hosts 問題
  • 問題描述
master | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}

在這裏插入圖片描述

  • 解決
# 方式一:
	免密登錄配置
# 方拾二:
	手動連接

在這裏插入圖片描述

  • 再次嘗試
[root@master ~]# ansible all -m ping -i /home/ansible-study/inventory/inventory.ini

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章