# Rename Network Interface

**URL:** <https://forum.ansible.com/t/rename-network-interface/835>\
**Category:** Get Help\
**Tags:** playbook, network\
**Created:** [September 15, 2023, 8:24pm UTC](https://forum.ansible.com/t/rename-network-interface/835 "2023-09-15T20:24:56Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 22, 2023, 7:57pm UTC](https://forum.ansible.com/t/rename-network-interface/835/22 "2023-09-22T19:57:33Z")

</div>

This is untested, but maybe instead of:

`ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",`

what about something like this:

```txt
ATTR{address}=="{{ ansible_facts[item]['perm_macaddress']
                   | default(ansible_facts[item]['macaddress']
                             | default(ansible_facts[item | regex_replace('^(.*)_\d+$', '\1')]['macaddress']
                                      )
                            )
                }}",

```

or another way to spell it, also untested:

```txt
ATTR{address}=="{{ ansible_facts[item]['perm_macaddress']
                   | default(ansible_facts[item
                                           if ansible_facts[item]['macaddress'] is defined
                                           else item | regex_replace('^(.*)_\d+$', '\1')
                                          ]['macaddress']
                            )
                }}",

```

I don’t like to post untested code, but I think one can work out the details of what I’m trying to do. 🙂

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 22, 2023, 8:06pm UTC](https://forum.ansible.com/t/rename-network-interface/835/23 "2023-09-22T20:06:10Z")

</div>

Nowadays those file has been created to first interface eth0 \>\> eno0 It means udev rules is created but got a looping when try secondary interface… drop udev and don’t work on ifcfg file… I’ll be happy just if I can just bring down secondary interfaces (some hosts I have more than one 🙂 ) or just ignore…  
Is these ATTR line just related rules right ? I guess feasible to work with (with\_items or add something with (with\_list) ?

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 22, 2023, 8:42pm UTC](https://forum.ansible.com/t/rename-network-interface/835/24 "2023-09-22T20:42:03Z")

</div>

Hi Todd

Looks like first option will work… not sure secondary …  
[root@lit-vatst2-q002 ~]# ip add  
1: lo: \<LOOPBACK,UP,LOWER\_UP\> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000  
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
inet 127.0.0.1/8 scope host lo  
valid\_lft forever preferred\_lft forever  
2: eth0: \<BROADCAST,MULTICAST,UP,LOWER\_UP\> mtu 1500 qdisc mq state UP group default qlen 1000  
link/ether 00:50:56:8d:b1:b5 brd ff:ff:ff:ff:ff:ff  
inet 10.132.78.194/23 brd 10.132.79.255 scope global eth0  
valid\_lft forever preferred\_lft forever  
inet 10.132.78.195/23 brd 10.132.79.255 scope global secondary eth0:1  
valid\_lft forever preferred\_lft forever  
3: eth1: \<BROADCAST,MULTICAST,UP,LOWER\_UP\> mtu 1500 qdisc mq state UP group default qlen 1000  
link/ether 00:50:56:8d:ef:82 brd ff:ff:ff:ff:ff:ff  
inet 10.132.196.253/23 brd 10.132.197.255 scope global eth1  
valid\_lft forever preferred\_lft forever  
[root@lit-vatst2-q002 ~]# cd /etc/sysconfig/network-scripts/  
[root@lit-vatst2-q002 network-scripts]# ls  
ifcfg-eno0 ifcfg-eth0.bak ifdown ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global  
ifcfg-eno1 ifcfg-eth1.bak ifdown-bnep ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions  
ifcfg-eth0:1 ifcfg-lo ifdown-eth ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6  
[root@lit-vatst2-q002 network-scripts]# cat /etc/udev/rules.d/  
69-vdo-start-by-dev.rules 70-rhosp-persistent-net.rules  
[root@lit-vatst2-q002 network-scripts]# cat /etc/udev/rules.d/70-rhosp-persistent-net.rules  
SUBSYSTEM==“net”, ACTION==“add”, DRIVERS==“?_“, ATTR{address}==“00:50:56:8d:b1:b5”, NAME=“eno0”  
SUBSYSTEM==“net”, ACTION==“add”, DRIVERS==”?_”, ATTR{address}==“00:50:56:8d:b1:b5”, NAME=“eno0\_1”  
SUBSYSTEM==“net”, ACTION==“add”, DRIVERS==“?\*”, ATTR{address}==“00:50:56:8d:ef:82”, NAME=“eno1”  
[root@lit-vatst2-q002 network-scripts]#

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 22, 2023, 8:45pm UTC](https://forum.ansible.com/t/rename-network-interface/835/25 "2023-09-22T20:45:21Z")

</div>

ok: [10.132.78.194]  
META: ran handlers

TASK [Debug message] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /app/awxtmp/bwrap\_2947910\_zlz459co/awx\_2947910\_kd8\_l28h/project/replace\_nic\_ethx.yml:12  
ok: [10.132.78.194] =\> {  
“src\_interfaces”: [  
“eth0”,  
“eth0\_1”,  
“eth1”  
]  
}

changed: [10.132.78.194] =\> (item=eth0) =\> {  
“backup”: “”,  
“changed”: true,  
“diff”: [  
{  
“after”: “”,  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”,  
“before”: “”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”  
},  
{  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”  
}  
],  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backrefs”: false,  
“backup”: false,  
“content”: null,  
“create”: true,  
“delimiter”: null,  
“directory\_mode”: null,  
“firstmatch”: false,  
“follow”: false,  
“force”: null,  
“group”: null,  
“insertafter”: null,  
“insertbefore”: null,  
“line”: “SUBSYSTEM==\“net\”, ACTION==\“add\”, DRIVERS==\”?\*\“, ATTR{address}==\“00:50:56:8d:b1:b5\”, NAME=\“eno0\””,  
“mode”: null,  
“owner”: null,  
“path”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules”,  
“regexp”: null,  
“remote\_src”: null,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: null,  
“state”: “present”,  
“unsafe\_writes”: null,  
“validate”: null  
}  
},  
“item”: “eth0”,  
“msg”: “line added”  
}

\\“?_\\“, ATTR{address}==\\“00:50:56:8d:b1:b5\\”, NAME=\\“eno0\_1\\””, “src”: null, “seuser”: null, “delimiter”: null, “mode”: null, “firstmatch”: false, “attributes”: null, “backup”: false}}}\n’, ‘’)  
changed: [10.132.78.194] =\> (item=eth0\_1) =\> {  
“backup”: “”,  
“changed”: true,  
“diff”: [  
{  
“after”: “”,  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”,  
“before”: “”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”  
},  
{  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”  
}  
],  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backrefs”: false,  
“backup”: false,  
“content”: null,  
“create”: true,  
“delimiter”: null,  
“directory\_mode”: null,  
“firstmatch”: false,  
“follow”: false,  
“force”: null,  
“group”: null,  
“insertafter”: null,  
“insertbefore”: null,  
“line”: “SUBSYSTEM==\“net\”, ACTION==\“add\”, DRIVERS==\”?_\”, ATTR{address}==\“00:50:56:8d:b1:b5\”, NAME=\“eno0\_1\”",  
“mode”: null,  
“owner”: null,  
“path”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules”,  
“regexp”: null,  
“remote\_src”: null,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: null,  
“state”: “present”,  
“unsafe\_writes”: null,  
“validate”: null  
}  
},  
“item”: “eth0\_1”,  
“msg”: “line added”  
}

\\“?_\\“, ATTR{address}==\\“00:50:56:8d:ef:82\\”, NAME=\\“eno1\\””, “src”: null, “seuser”: null, “delimiter”: null, “mode”: null, “firstmatch”: false, “attributes”: null, “backup”: false}}}\n’, ‘’)  
changed: [10.132.78.194] =\> (item=eth1) =\> {  
“backup”: “”,  
“changed”: true,  
“diff”: [  
{  
“after”: “”,  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”,  
“before”: “”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)”  
},  
{  
“after\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”,  
“before\_header”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)”  
}  
],  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backrefs”: false,  
“backup”: false,  
“content”: null,  
“create”: true,  
“delimiter”: null,  
“directory\_mode”: null,  
“firstmatch”: false,  
“follow”: false,  
“force”: null,  
“group”: null,  
“insertafter”: null,  
“insertbefore”: null,  
“line”: “SUBSYSTEM==\“net\”, ACTION==\“add\”, DRIVERS==\”?_\”, ATTR{address}==\“00:50:56:8d:ef:82\”, NAME=\“eno1\”",  
“mode”: null,  
“owner”: null,  
“path”: “/etc/udev/rules.d/70-rhosp-persistent-net.rules”,  
“regexp”: null,  
“remote\_src”: null,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: null,  
“state”: “present”,  
“unsafe\_writes”: null,  
“validate”: null  
}  
},  
“item”: “eth1”,  
“msg”: “line added”  
}

TASK [Check that src\_prefix files exists] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Replace interface name in config.json] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /app/awxtmp/bwrap\_2947910\_zlz459co/awx\_2947910\_kd8\_l28h/project/replace\_nic\_ethx.yml:192  
skipping: [10.132.78.194] =\> (item=eth0) =\> {  
“changed”: false,  
“item”: “eth0”,  
“skip\_reason”: “Conditional result was False”  
}  
skipping: [10.132.78.194] =\> (item=eth0\_1) =\> {  
“changed”: false,  
“item”: “eth0\_1”,  
“skip\_reason”: “Conditional result was False”  
}  
skipping: [10.132.78.194] =\> (item=eth1) =\> {  
“changed”: false,  
“item”: “eth1”,  
“skip\_reason”: “Conditional result was False”  
}  
META: ran handlers  
META: ran handlers

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
10.132.78.194 : ok=15 changed=7 unreachable=0 failed=0

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 22, 2023, 8:49pm UTC](https://forum.ansible.com/t/rename-network-interface/835/26 "2023-09-22T20:49:52Z")

</div>

mmm first option messed up interface 1 after reboot eth0 \>\> eno0\_1

Lemme test option 2

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 22, 2023, 9:08pm UTC](https://forum.ansible.com/t/rename-network-interface/835/27 "2023-09-22T21:08:12Z")

</div>

No luck option 2 doesn’t work at all… it is creating eno0 and eno0\_1 into udev with same mac addr… but its faling on ifcfg-eno0 and ifcfg-eno0\_1 that creating one device as eno0\_1 and no secondary…

I guess the best way would be to ignore or bring down secondary interface…

😑

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 22, 2023, 9:29pm UTC](https://forum.ansible.com/t/rename-network-interface/835/28 "2023-09-22T21:29:18Z")

</div>

I’ve been [reading up](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/consistent-network-interface-device-naming_configuring-and-managing-networking#doc-wrapper) on device names vs interface names. (It’s a RHEL-8 doc, but similar enough at the higher levels I think.) We may be mixing up things. I think there’s only one **device** named initially `eth0` but renamed via udev to `eno0`, and it has a MAC address. But there are two **interfaces** as described/defined in `ifcfg-eno0` and `ifcfg_eno0_1`, both of which map to a single device.

I’d suggest dropping the udev rule for `eno0_1` because it’s bogus. Use udev to define device `eno0`, and use `ifcfg-*` files to create the two interfaces, both of which are on the `eno0` device.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 22, 2023, 9:35pm UTC](https://forum.ansible.com/t/rename-network-interface/835/29 "2023-09-22T21:35:20Z")

</div>

If that’s right, then add a `when:` on your “Update udev rules” task:

```txt
when: ansible_facts[item]['macaddress'] is defined

```

You don’t want/need the `ipv4_secondaries` for the udev rules, but you will need them for the `ifcfg-*` interface definitions.

---

<div class="post-metadata">

**Author:** ![bspigari](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bspigari/32/789_2.png) [@bspigari](https://forum.ansible.com/u/bspigari)\
**Post date:** [September 27, 2023, 9:42pm UTC](https://forum.ansible.com/t/rename-network-interface/835/30 "2023-09-27T21:42:21Z")

</div>

Yeh Todd

You’re a rock star ! Its work to me

````auto
- name: Update udev rules
      tags:
        - udev
      when: ansible_facts[item]['macaddress'] is defined  
      lineinfile:
        line: >
          SUBSYSTEM=="net",
          ACTION=="add",
          DRIVERS=="?*",
          ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",
          NAME="{{ item | replace(src_prefix, dst_prefix) }}"
        path: /etc/udev/rules.d/70-rhosp-persistent-net.rules
        create: true
      with_items: "{{ src_interfaces | reject('match', '^.*\\..*$') | list }}"```

- name: Update udev rules
      tags:
        - udev
      when: ansible_facts[item]['macaddress'] is defined  
      lineinfile:
        line: >
          SUBSYSTEM=="net",
          ACTION=="add",
          DRIVERS=="?*",
          ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",
          NAME="{{ item | replace(src_prefix, dst_prefix) }}"
        path: /etc/udev/rules.d/70-rhosp-persistent-net.rules
        create: true
      with_items: "{{ src_interfaces | reject('match', '^.*\\..*$') | list }}"`

I just need to fix secondary IP after migration but ok :slight_smile:
````

---

<div class="post-metadata">

**Author:** ![gwmngilfen](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gwmngilfen/32/6_2.png) [@gwmngilfen](https://forum.ansible.com/u/gwmngilfen)\
**Post date:** [September 27, 2023, 10:10pm UTC](https://forum.ansible.com/t/rename-network-interface/835/31 "2023-09-27T22:10:42Z")

</div>

Since it was @utoddl who got you on the right path, I’ve moved the Solution to his post. Solutions are a big part of how we recognise contributions in the #Get Help category, so this seems right here.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 27, 2023, 10:10pm UTC](https://forum.ansible.com/t/rename-network-interface/835/32 "2023-10-27T22:10:47Z")

</div>

Closed on October 27, 2023, 10:10pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.ansible.com/t/rename-network-interface/835.md?page=1)
