Skip to content

Commit 0f440ee

Browse files
committed
fix slurm.conf inventory filtering for nodenames with padding
1 parent c79d203 commit 0f440ee

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

filter_plugins/slurm_conf.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ def hostlist_expression(hosts):
3838
E.g. with an inventory containing:
3939
4040
[compute]
41-
dev-foo-0 ansible_host=localhost
42-
dev-foo-3 ansible_host=localhost
41+
dev-foo-00 ansible_host=localhost
42+
dev-foo-3 ansible_host=localhost
4343
my-random-host
44-
dev-foo-4 ansible_host=localhost
45-
dev-foo-5 ansible_host=localhost
46-
dev-compute-0 ansible_host=localhost
47-
dev-compute-1 ansible_host=localhost
44+
dev-foo-04 ansible_host=localhost
45+
dev-foo-05 ansible_host=localhost
46+
dev-compute-000 ansible_host=localhost
47+
dev-compute-001 ansible_host=localhost
4848
4949
Then "{{ groups[compute] | hostlist_expression }}" will return:
5050
51-
["dev-foo-[0,3-5]", "dev-compute-[0-1]", "my-random-host"]
51+
['dev-foo-[00,04-05,3]', 'dev-compute-[000-001]', 'my-random-host']
5252
"""
5353

5454
results = {}
@@ -57,21 +57,24 @@ def hostlist_expression(hosts):
5757
m = pattern.match(v)
5858
if m:
5959
prefix, suffix = m.groups()
60+
print(prefix,suffix)
6061
r = results.setdefault(prefix, [])
61-
r.append(int(suffix))
62+
r.append(suffix)
6263
else:
6364
unmatchable.append(v)
6465
return ['{}[{}]'.format(k, _group_numbers(v)) for k, v in results.items()] + unmatchable
6566

6667
def _group_numbers(numbers):
68+
print('numbers:', sorted(numbers))
6769
units = []
68-
prev = min(numbers)
70+
prev = min(int(n) for n in numbers)
6971
for v in sorted(numbers):
70-
if v == prev + 1:
72+
if int(v) == prev + 1:
7173
units[-1].append(v)
7274
else:
7375
units.append([v])
74-
prev = v
76+
print('units:', units)
77+
prev = int(v)
7578
return ','.join(['{}-{}'.format(u[0], u[-1]) if len(u) > 1 else str(u[0]) for u in units])
7679

7780
def error(condition, msg):

0 commit comments

Comments
 (0)