diff --git a/roles/facts/files/memory.fact b/roles/facts/files/memory.fact index ced76c126..dad229622 100644 --- a/roles/facts/files/memory.fact +++ b/roles/facts/files/memory.fact @@ -1,2 +1,5 @@ #!/bin/bash -echo "{ \"total_mb\": $(free -m | grep Mem: | awk '{print $2*0.95}') }" \ No newline at end of file +# printf "%d" keeps the value an integer regardless of locale: the default +# awk print emits a float whose decimal separator follows LC_NUMERIC, which +# on comma-decimal locales produces invalid JSON and breaks the local fact. +echo "{ \"total_mb\": $(free -m | awk '/^Mem:/ {printf "%d", $2*0.95}') }" diff --git a/roles/slurm/templates/etc/slurm/slurm.conf b/roles/slurm/templates/etc/slurm/slurm.conf index 73015cd96..91d946007 100644 --- a/roles/slurm/templates/etc/slurm/slurm.conf +++ b/roles/slurm/templates/etc/slurm/slurm.conf @@ -133,6 +133,10 @@ GresTypes=gpu {% endif %} {% for node_name in groups['slurm-node'] %} {% set memory = hostvars[node_name]["ansible_local"]["memory"] -%} +{# If the custom fact failed JSON parsing Ansible hands us a string; + parse it here so a bad fact fails loudly instead of with an opaque + attribute error on total_mb. -#} +{% if memory is string %}{% set memory = memory | from_json -%}{% endif -%} {% set cpu_topology = hostvars[node_name]["ansible_local"]["topology"]["cpu_topology"] -%} {% set gpu_topology = hostvars[node_name]["ansible_local"]["topology"]["gpu_topology"] -%} NodeName={{ node_name }}{{ " " -}}