fix: make memory fact locale-safe and integer-valued#1364
Merged
Conversation
The memory custom fact computed total_mb with awk's default print,
which emits a float (e.g. 60760.1) whose decimal separator follows
LC_NUMERIC. On comma-decimal locales the fact rendered as
{ "total_mb": 60760,1 } — invalid JSON — so Ansible fell back to
providing the fact as a raw string and slurm.conf templating failed
with an opaque AnsibleUnsafeText attribute error on total_mb.
Use printf "%d" so the value is always an integer with no locale-
dependent formatting (RealMemory expects an integer anyway), and
harden the slurm.conf template to parse a string fact so a malformed
fact fails clearly rather than with an attribute error.
Fixes #1321
Contributor
Author
Live validation summaryValidated on a disposable dual-GPU server (Ubuntu 22.04) with a fresh full
|
michael-balint
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
memorycustom fact locale-safe and integer-valued: computetotal_mbwithawk printf "%d"instead of the default floatprint.LC_NUMERICdecimal separator. On comma-decimal locales the fact emitted{ "total_mb": 60760,1 }— invalid JSON — so Ansible silently provided the fact as a raw string andslurm.conftemplating failed with the reportedAnsibleUnsafeText ... has no attribute 'total_mb'error. This also explains why the error only reproduced for some users: it depends on the host locale.slurm.conftemplate to parse a string-typed fact (from_json) so any future malformed fact fails clearly instead of with an opaque attribute error.Validation
bash -non the fact script; the fact output parses as JSON with an integertotal_mb.awk '{print $2*0.95}'emits60760.1(locale-dependent separator),printf "%d"cannot emit a separator.ansible-playbook --syntax-check playbooks/slurm-cluster.yml; full role lint: 0 failures.RealMemorytemplates as an integer and the fact parses under a comma-decimal locale on the deployed node.Notes
printf "%d"truncates toward zero, preserving the intended 5% headroom; output is unchanged on hosts where the value was already integral.