Skip to content

Commit 9b76a5e

Browse files
authored
Output slurm config as facts (#176)
* output slurm config as facts * address linter errors * fix facts parsing 'SlurmctldParameters = enable_configlessReturnToService=2' * remove out of date test7 * skip broken mariadb on RL8
1 parent 31017d2 commit 9b76a5e

File tree

11 files changed

+78
-85
lines changed

11 files changed

+78
-85
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ jobs:
5353
- test4
5454
- test5
5555
- test6
56-
- test7
5756
- test8
5857
- test9
5958
- test10
6059
- test11
6160
- test12
6261
- test13
6362
- test14
64-
exclude: []
63+
exclude:
64+
# mariadb package provides /usr/bin/mysql on RL8 which doesn't work with geerlingguy/mysql role
65+
- scenario: test4
66+
image: 'rockylinux:8.9'
6567

6668
steps:
6769
- name: Check out the codebase.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ You will need to configure these variables if you have set `openhpc_enable.datab
136136

137137
`openhpc_slurmdbd_mysql_username`: Username for authenticating with the database, defaults to `slurm`.
138138

139+
## Facts
140+
141+
This role creates local facts from the live Slurm configuration, which can be
142+
accessed (with facts gathering enabled) using `ansible_local.slurm`. As per the
143+
`scontrol show config` man page, uppercase keys are derived parameters and keys
144+
in mixed case are from from config files. Note the facts are only refreshed
145+
when this role is run.
146+
139147
## Example Inventory
140148

141149
And an Ansible inventory as this:

filter_plugins/slurm_conf.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,46 @@ def dict2parameters(d):
9191
parts = ['%s=%s' % (k, v) for k, v in d.items()]
9292
return ' '.join(parts)
9393

94+
def config2dict(lines):
95+
""" Convert a sequence of output lines from `scontrol show config` to a dict.
96+
97+
As per man page uppercase keys are derived parameters, mixed case are from
98+
from config files.
99+
100+
The following case-insensitive conversions of values are carried out:
101+
- '(null)' and 'n/a' are converted to None.
102+
- yes and no are converted to True and False respectively
103+
104+
Except for these, values are always strings.
105+
"""
106+
cfg = {}
107+
for line in lines:
108+
if '=' not in line: # ditch blank/info lines
109+
continue
110+
else:
111+
parts = [x.strip() for x in line.split('=', maxsplit=1)] # maxplit handles '=' in values
112+
if len(parts) != 2:
113+
raise errors.AnsibleFilterError(f'line {line} cannot be split into key=value')
114+
k, v = parts
115+
small_v = v.lower()
116+
if small_v == '(null)':
117+
v = None
118+
elif small_v == 'n/a':
119+
v = None
120+
elif small_v == 'no':
121+
v = False
122+
elif small_v == 'yes':
123+
v = True
124+
cfg[k] = v
125+
return cfg
126+
127+
94128
class FilterModule(object):
95129

96130
def filters(self):
97131
return {
98132
'hostlist_expression': hostlist_expression,
99133
'error': error,
100134
'dict2parameters': dict2parameters,
135+
'config2dict': config2dict,
101136
}

handlers/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@
6666
- openhpc_slurm_service_started | bool
6767
- openhpc_enable.batch | default(false) | bool
6868
# 2nd condition required as notification happens on controller, which isn't necessarily a compute note
69+
70+
- name: Reload facts
71+
ansible.builtin.setup:
72+
filter: ansible_local

molecule/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test3 | 1 | Y | -
1414
test4 | 1 | N | 2x compute node, accounting enabled
1515
test5 | 1 | N | As for #1 but configless
1616
test6 | 1 | N | 0x compute nodes, configless
17-
test7 | 1 | N | 1x compute node, no login node so specified munge key, configless (checks image build should work)
17+
test7 | 1 | N | [removed, image build should just run install.yml task, this is not expected to work]
1818
test8 | 1 | N | 2x compute node, 2x login-only nodes, configless
1919
test9 | 1 | N | As test8 but uses `--limit=testohpc-control,testohpc-compute-0` and checks login nodes still end up in slurm.conf
2020
test10 | 1 | N | As for #5 but then tries to add an additional node

molecule/test7/converge.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

molecule/test7/molecule.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Binary file not shown.

molecule/test7/verify.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

tasks/facts.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- name: Capture configuration from scontrol
2+
# this includes any dynamically-generated config, not just what is set in
3+
# slurm.conf
4+
ansible.builtin.command: scontrol show config
5+
changed_when: false
6+
register: _scontrol_config
7+
8+
- name: Create facts directory
9+
ansible.builtin.file:
10+
path: /etc/ansible/facts.d/
11+
state: directory
12+
owner: root
13+
group: root
14+
mode: ugo=rwX
15+
16+
- name: Template slurm configuration facts
17+
copy:
18+
dest: /etc/ansible/facts.d/slurm.fact
19+
content: "{{ _scontrol_config.stdout_lines | config2dict | to_nice_json }}"
20+
owner: slurm
21+
group: slurm
22+
mode: ug=rw,o=r # any user can run scontrol show config anyway
23+
register: _template_facts
24+
notify: Reload facts

tasks/runtime.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,5 @@
216216
enabled: "{{ openhpc_slurm_service_enabled | bool }}"
217217
state: "{{ 'started' if openhpc_slurm_service_started | bool else 'stopped' }}"
218218
when: openhpc_enable.batch | default(false) | bool
219+
220+
- import_tasks: facts.yml

0 commit comments

Comments
 (0)