This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
---
|
||||
- name: Discover node resources for Slurm config
|
||||
hosts: slurm_cluster
|
||||
become: true
|
||||
gather_facts: true
|
||||
|
||||
tasks:
|
||||
- name: Discover CPU and memory
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
echo "HOST={{ inventory_hostname }}"
|
||||
echo "CPUS=$(nproc)"
|
||||
echo "REAL_MEMORY_MB=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)"
|
||||
echo "SOCKETS=$(lscpu | awk -F: '/Socket\\(s\\)/ {gsub(/ /,\"\",$2); print $2}')"
|
||||
echo "CORES_PER_SOCKET=$(lscpu | awk -F: '/Core\\(s\\) per socket/ {gsub(/ /,\"\",$2); print $2}')"
|
||||
echo "THREADS_PER_CORE=$(lscpu | awk -F: '/Thread\\(s\\) per core/ {gsub(/ /,\"\",$2); print $2}')"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: cpu_mem
|
||||
changed_when: false
|
||||
|
||||
- name: Discover NVIDIA GPU if present
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
if command -v nvidia-smi >/dev/null 2>&1; then
|
||||
nvidia-smi --query-gpu=index,name,memory.total --format=csv,noheader
|
||||
else
|
||||
echo "NO_NVIDIA_SMI"
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: gpu_info
|
||||
changed_when: false
|
||||
|
||||
- name: Show discovered resources
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "{{ cpu_mem.stdout_lines }}"
|
||||
- "GPU:"
|
||||
- "{{ gpu_info.stdout_lines }}"
|
||||
Reference in New Issue
Block a user