使用ansible批量查看虚拟机网卡名称
时间: 2024-04-09 19:32:47 浏览: 152
您可以使用 Ansible 的 `gather_facts` 模块来收集虚拟机的网络接口信息,然后使用 `debug` 模块打印出网卡名称。下面是一个示例的 Ansible playbook:
```yaml
---
- name: Gather network interface facts
hosts: your_host_group
tasks:
- name: Gather facts
gather_facts: yes
- name: Print network interfaces
debug:
var: ansible_facts['ansible_interfaces']
```
请将 `your_host_group` 替换为您要操作的主机组名称。运行该 playbook 后,Ansible 将会收集主机的网络接口信息,并打印出网卡名称。
注意:您需要确保在执行 playbook 时已经配置了正确的 SSH 认证信息,并且目标主机能够正常连接。
阅读全文