Skip to content

Commit

Permalink
Remove ens3 also from NetworkManager config
Browse files Browse the repository at this point in the history
In CentOS 9/Rocky Linux 9/clones cloud images there is
/etc/NetworkManager/system-connections/ens3.nmconnection
Let's do the same treatment as for CentOS 8 network-scripts.
  • Loading branch information
mnasiadka committed Oct 11, 2023
1 parent 57287dc commit c869d5c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
- interfaces_route_tables | length > 0
notify: Restart NetworkManager

# CentOS 8 cloud images ship with ifcfg files for ens3 and eth0. ifcfg-ens3
# CentOS 8/9 cloud images ship with ifcfg files for ens3 and eth0. ifcfg-ens3
# seems to be a relic from the image build process, and causes the network
# service to fail. ifcfg-eth0 is useful for most virtual machines, but if a
# cloud image is deployed on bare metal and eth0 is absent, the network service
# will fail. Remove these files if the interface does not exist or is not being
# configured.

- name: RedHat | remove invalid interface configuration
- name: RedHat | network-scripts remove invalid interface configuration
become: true
file:
path: "/etc/sysconfig/network-scripts/ifcfg-{{ item }}"
Expand All @@ -40,6 +40,20 @@
- item not in interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list
with_items: "{{ interfaces_workaround_centos_remove }}"

- name: RedHat | network-manager remove invalid interface configuration
become: true
file:
path: "/etc/NetworkManager/system-connections/{{ item }}.nmconnection"
state: absent
when:
- item not in ansible_facts.interfaces
- item not in interfaces_ether_interfaces | map(attribute='device') | list
- item not in interfaces_bridge_interfaces | map(attribute='device') | list
- item not in interfaces_bridge_interfaces | map(attribute='ports') | flatten | list
- item not in interfaces_bond_interfaces | map(attribute='device') | list
- item not in interfaces_bond_interfaces | map(attribute='bond_slaves') | flatten | list
with_items: "{{ interfaces_workaround_centos_remove }}"

# When using NetworkManager with system-connections store, existing ifcfg files
# need to be removed, otherwise they shadow our nmconnection files. We do this
# only for interfaces that we manage in this role.
Expand Down

0 comments on commit c869d5c

Please sign in to comment.