4.3. 为 undercloud 节点使用可预测的 NIC 名称


在 undercloud 节点上运行 Leapp 升级前,您必须检查基于内核的 NIC 名称,这通常包含 eth 前缀。在 NIC 分配方面,这些 NIC 名称通常无法预计。

您可以运行 playbook-nics.yaml playbook 来重命名 NIC 名称,以使用 em NIC 前缀。您还可以在运行 playbook 时修改前缀变量来设置不同的 NIC 前缀。但是,NIC 更改仅在 Leapp 升级过程完成后应用,并重新引导节点。

流程

  1. stack 用户的身份登录 undercloud。
  2. 创建名为 playbook-nics.yaml 的 Ansible playbook,并将以下内容复制到 playbook 中:

    ---
    - name: Rename eth devices
      hosts: all
      become: yes
      vars:
        prefix: "em"
        undercloud_conf: "/home/stack/undercloud.conf"
        osnet_conf: "/etc/os-net-config/config.json"
      tasks:
        - set_fact:
            eth_interfaces: "{{ ansible_interfaces | select('match','eth.*') | list }}"
        - debug:
            msg: "{{ eth_interfaces }}"
        - name: Update udev rules
          lineinfile:
            line: "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}\", NAME=\"{{ item|replace('eth',prefix) }}\""
            path: /etc/udev/rules.d/70-rhosp-persistent-net.rules
            create: True
          with_items: "{{ eth_interfaces }}"
        - name: Rename eth files
          block:
            - name: Check that eth files exists
              stat:
                path: /etc/sysconfig/network-scripts/ifcfg-{{ item }}
              register: nic_result
              with_items: "{{ eth_interfaces }}"
            - name: Copy nic files using the new prefix
              copy:
                remote_src: True
                src: "{{ item.stat.path }}"
                dest: "{{ item.stat.path|replace('eth',prefix) }}"
              with_items: "{{ nic_result.results }}"
              when: item.stat.exists
            - name: Edit NAME in new network-script files
              lineinfile:
                regexp: "^NAME=.*"
                line: "NAME={{ item.item|replace('eth',prefix) }}"
                path: "{{ item.stat.path|replace('eth',prefix) }}"
              with_items: "{{ nic_result.results }}"
              when: item.stat.exists
            - name: Edit DEVICE in new network-script files
              lineinfile:
                regexp: "^DEVICE=.*"
                line: "DEVICE={{ item.item|replace('eth',prefix) }}"
                path: "{{ item.stat.path|replace('eth',prefix) }}"
              with_items: "{{ nic_result.results }}"
              when: item.stat.exists
            - name: Backup old eth network-script files
              copy:
                remote_src: True
                src: "{{ item.stat.path }}"
                dest: "{{ item.stat.path }}.bak"
              with_items: "{{ nic_result.results }}"
              when: item.stat.exists
            - name: Remove old eth network-script files
              file:
                path: "{{ item.stat.path }}"
                state: absent
              with_items: "{{ nic_result.results }}"
              when: item.stat.exists
        - name: Rename route files
          block:
            - name: Check that route files exists
              stat:
                path: /etc/sysconfig/network-scripts/route-{{ item }}
              register: route_result
              with_items: "{{ eth_interfaces }}"
            - name: Copy route files using the new prefix
              copy:
                remote_src: True
                src: "{{ item.stat.path }}"
                dest: "{{ item.stat.path|replace('eth',prefix) }}"
              with_items: "{{ route_result.results }}"
              when: item.stat.exists
            - name: Update prefix in route files that use IP command arguments format
              replace:
                regexp: "eth"
                replace: "{{ prefix }}"
                path: "{{ item.stat.path|replace('eth',prefix) }}"
              with_items: "{{ route_result.results }}"
              when: item.stat.exists
            - name: Backup old route files
              copy:
                remote_src: True
                src: "{{ item.stat.path }}"
                dest: "{{ item.stat.path }}.bak"
              with_items: "{{ route_result.results }}"
              when: item.stat.exists
            - name: Remove old route files
              file:
                path: "{{ item.stat.path }}"
                state: absent
              with_items: "{{ route_result.results }}"
              when: item.stat.exists
        - name: Perform a final regex for any remaining eth prefixes in ifcfg files
          block:
            - name: Get a list of all ifcfg files
              find:
                paths: /etc/sysconfig/network-scripts/
                patterns: 'ifcfg-*'
                excludes: '*.bak'
              register: ifcfg_files
            - name: Perform final regex on ifcfg files
              replace:
                path: "{{ item[0].path }}"
                regexp: "{{ item[1] }}"
                replace: "{{ item[1]|replace('eth',prefix) }}"
              with_nested:
                - "{{ ifcfg_files.files }}"
                - "{{ eth_interfaces }}"
        - name: Replace interface name in files referencing old eth interface
          block:
            - name: Check if undercloud.conf exists
              stat:
                path: "{{ undercloud_conf }}"
              register: undercloud_conf_stat
            - name: Replace interface name in undercloud.conf
              replace:
                path: "{{ undercloud_conf }}"
                regexp: 'eth(\d+)'
                replace: "{{ prefix }}\\1"
              when: undercloud_conf_stat.stat.exists
            - name: Check if os-net-config's config.json exists
              stat:
                path: "{{ osnet_conf }}"
              register: osnet_conf_stat
            - name: Replace interface name in config.json
              replace:
                path: "{{ osnet_conf }}"
                regexp: 'eth(\d+)'
                replace: "{{ prefix }}\\1"
              when: osnet_conf_stat.stat.exists
        - name: Patch vlan devices
          block:
            - name: Check that vlan files exists
              stat:
                path: /etc/sysconfig/network-scripts/ifcfg-{{ item }}
              register: nic_result
              when: item.startswith("vlan")
              with_items: "{{ ansible_interfaces }}"
            - name: Backup old vlan network-script files
              copy:
                remote_src: True
                src: "{{ item.stat.path }}"
                dest: "{{ item.stat.path }}.bak"
              when: item.item.startswith("vlan") and item.stat.exists
              with_items: "{{ nic_result.results }}"
            - name: Edit PHYSDEV in new network-script files
              replace:
                path: "{{ item.stat.path }}"
                regexp: "^PHYSDEV=eth"
                replace: "PHYSDEV={{ prefix }}"
              when: item.item.startswith("vlan") and item.stat.exists
              with_items: "{{ nic_result.results }}"
    Copy to Clipboard Toggle word wrap
    注意

    您将在升级过程中使用此 playbook 在稍后阶段重命名 overcloud NIC。

  3. 在 undercloud 上运行 playbook-nics.yaml playbook:

    $ ansible-playbook -c local -i localhost, playbook-nics.yaml
    Copy to Clipboard Toggle word wrap

    playbook 将新的 NIC 前缀设置为 em。要设置不同的 NIC 前缀,请在运行 playbook 时设置 前缀 变量:

    $ ansible-playbook -c local -i localhost, -e prefix="mynic" ~/playbook-nics.yaml
    Copy to Clipboard Toggle word wrap

    NIC 更改仅在 Leapp 升级过程完成且重新引导节点后应用。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat