You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ovirt通过Ansible部署VM后无IP地址及DNS问题求助

问题诊断与修复方案

我帮你分析了一下你的Ansible Playbook,问题主要出在网卡配置不匹配和缺失关键网络参数这几个地方,具体来看:

1. 网卡名称不匹配是核心问题

你的nics字段定义的VM网卡在oVirt侧叫vnet0,但cloud_init里指定的nic_name: eth1是VM操作系统内部的网卡名称——这里明显不匹配:

  • oVirt侧的vnet0是宿主机对这块网卡的标识,VM内部看到的第一块网卡通常是eth0(RHEL 7默认是这个命名)
  • 你指定了eth1,但VM里只有一块网卡,cloud-init找不到对应的网卡,自然无法配置静态IP

修复方法:
要么把nic_name改成VM内部实际的网卡名eth0,要么直接删掉这个参数,让cloud-init自动匹配第一块网卡:

cloud_init:
  nic_boot_protocol: static
  nic_ip_address: 10.34.60.86
  nic_netmask: 255.255.252.0
  nic_gateway: 10.34.63.254
  # 移除nic_name: eth1,或者替换为eth0
  nic_on_boot: true
  # ... 其他配置项

2. 缺失DNS服务器配置

你的Playbook里完全没设置DNS,这不仅会导致VM无法解析域名,部分RHEL 7系统的网络初始化依赖DNS配置,缺失后可能影响静态IP的正常生效。

修复方法:
在cloud_init里添加DNS服务器地址:

cloud_init:
  # ... 现有配置
  dns_servers:
    - 10.34.60.1  # 替换成你的实际内网DNS
    - 8.8.8.8      # 可选的公共DNS

3. 更规范的网卡配置方式(可选)

oVirt的cloud_init支持用nics列表格式来定义网卡配置,比单独的nic_*参数更清晰,也不容易出错,推荐改成这种写法:

cloud_init:
  nics:
    - name: eth0
      boot_protocol: static
      ip_address: 10.34.60.86
      netmask: 255.255.252.0
      gateway: 10.34.63.254
      on_boot: true
  # ... 其他配置(hostname、user等)

4. 调试验证步骤

如果调整后还是不行,建议通过oVirt控制台登录VM,查看cloud-init的日志来定位问题:

# 查看cloud-init执行日志
cat /var/log/cloud-init.log
# 查看cloud-init的输出日志(包含网络配置的具体过程)
cat /var/log/cloud-init-output.log

这两个日志会明确告诉你cloud-init在配置网络时有没有报错,比如找不到网卡、参数格式错误等。

5. 额外检查点

  • 确认ovirtmgmt网络的子网和你指定的10.34.60.86在同一个网段,且网络本身正常可用
  • 检查你的RHEL 7模板是否已经安装了cloud-init包,并且启用了cloud-init服务(模板必须支持cloud-init才能生效)
  • 确保Ansible的ovirt_vms模块版本和oVirt Engine 4.2兼容,避免版本不匹配导致的配置失效

调整后的完整Playbook片段

- name: Add vanilla vm
  ovirt_vms:
    auth: "{{ ovirt_auth }}"
    name: test01
    cluster: Default
    state: running
    memory: 2GiB
    cpu_cores: 8
    operating_system: rhel_7x64
    high_availability: true
    high_availability_priority: 50 # Available from Ansible 2.5
    cloud_init:
      nics:
        - name: eth0
          boot_protocol: static
          ip_address: 10.34.60.86
          netmask: 255.255.252.0
          gateway: 10.34.63.254
          on_boot: true
      host_name: test01.ovirt.dw
      dns_servers:
        - 10.34.60.1
        - 8.8.8.8
      custom_script: |
        write_files:
          - content: |
              Hello, world!
            path: /tmp/greeting.txt
            permissions: '0644'
      user_name: root
      root_password: super_password
    nics:
      - name: vnet0
        network: ovirtmgmt
        profile: ovirtmgmt
        interface: virtio

内容的提问来源于stack exchange,提问作者03ce007

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:16:46