- 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