- 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