Skip to content

Commit

Permalink
tests: Find unconfigured Ethernet interfaces with a permanent MAC add…
Browse files Browse the repository at this point in the history
…ress

Signed-off-by: Wen Liang <[email protected]>
  • Loading branch information
liangwen12year authored and Wen Liang committed Jan 23, 2025
1 parent 2439f44 commit 09897cd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/tests_find_unconfigured_ethernet_with_mac_nm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- name: Find unconfigured Ethernet interfaces with permanent MAC addresses
hosts: all
tasks:
- name: List all Ethernet interfaces
command: ls /sys/class/net/
register: interfaces

- name: Find unconfigured Ethernet interfaces with permanent MAC addresses
shell: |
results=()
for iface in {{ interfaces.stdout_lines | join(' ') }}; do
# Check if the interface is Ethernet (type = 1)
if [[ $(cat /sys/class/net/$iface/type) -eq 1 ]]; then
# Check if the interface has no IP address configured
if ! ip addr show "$iface" | grep -q "inet "; then
# Retrieve the permanent MAC address
mac=$(ethtool -P "$iface" 2>/dev/null | awk '{print $3}')
if [[ -n $mac && $mac != "not" ]]; then
results+=("$iface $mac")
fi
fi
fi
done
printf "%s\n" "${results[@]}"
register: unconfigured_interfaces
failed_when: false

- name: Display all unconfigured Ethernet interfaces with permanent MAC addresses
debug:
msg: "{{ unconfigured_interfaces.stdout_lines }}"

0 comments on commit 09897cd

Please sign in to comment.