在没有DNS或/etc/hosts解析的情况下连接节点,可以使用Ansible的inventory文件来指定节点的IP地址。以下是一个示例的解决方法:
[node1]
192.168.1.101
[node2]
192.168.1.102
- name: Example playbook
hosts: node1
tasks:
- name: Ping node
ping:
在上面的示例中,Ansible将连接到inventory中名为[node1]的节点,即IP地址为192.168.1.101的节点。
ansible-playbook -i inventory.ini playbook.yml
上述命令将使用inventory.ini文件中的节点信息来连接节点并执行playbook。
这种方法可以在没有DNS或/etc/hosts解析的情况下,通过直接指定节点的IP地址来连接节点。