perf: gather mac address

This commit is contained in:
wangruidong
2026-06-26 16:36:48 +08:00
committed by 老广
parent 68a39a92e5
commit 8b04d75421
3 changed files with 31 additions and 0 deletions

View File

@@ -24,6 +24,21 @@
kernel: "{{ ansible_kernel }}"
- name: Get MAC addresses
shell: |
for iface in $(ls /sys/class/net/ | grep -v '^lo$'); do
mac=$(cat /sys/class/net/$iface/address 2>/dev/null)
if [ -n "$mac" ] && [ "$mac" != "00:00:00:00:00:00" ]; then
echo "${iface}: ${mac}"
fi
done
register: mac_info
ignore_errors: yes
- name: Merge MAC info into final info
set_fact:
info: "{{ info | combine({'mac_address': mac_info.stdout_lines | default([])}) }}"
- name: Get GPU info with nvidia-smi
shell: |
nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv,noheader,nounits

View File

@@ -16,5 +16,16 @@
cpu_vcpus: "{{ ansible_processor_vcpus }}"
memory: "{{ (ansible_memtotal_mb / 1024) | round(2) }}"
- name: Get MAC addresses on Windows
win_shell: |
Get-NetAdapter | Where-Object { $_.MacAddress -and $_.MacAddress -ne '00-00-00-00-00-00' } |
ForEach-Object { "$($_.Name): $($_.MacAddress -replace '-', ':')" }
register: mac_info
ignore_errors: yes
- name: Merge MAC info into final info
set_fact:
info: "{{ info | combine({'mac_address': mac_info.stdout_lines | default([])}) }}"
- debug:
var: info

View File

@@ -18,6 +18,11 @@ class HostGatheredInfoSerializer(serializers.Serializer):
arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch'))
gpu_model = serializers.CharField(allow_blank=True, required=False, label=_('GPU model'))
mac_address = serializers.ListField(
child=serializers.CharField(allow_blank=True),
required=False,
label=_('MAC address'),
)
category_gathered_serializer_map = {