File tree Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Original file line number Diff line number Diff 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
141149And an Ansible inventory as this:
Original file line number Diff line number Diff line change @@ -91,11 +91,43 @@ 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+ k , v = (x .strip () for x in line .split ('=' ))
112+ small_v = v .lower ()
113+ if small_v == '(null)' :
114+ v = None
115+ elif small_v == 'n/a' :
116+ v = None
117+ elif small_v == 'no' :
118+ v = False
119+ elif small_v == 'yes' :
120+ v = True
121+ cfg [k ] = v
122+ return cfg
123+
124+
94125class FilterModule (object ):
95126
96127 def filters (self ):
97128 return {
98129 'hostlist_expression' : hostlist_expression ,
99130 'error' : error ,
100131 'dict2parameters' : dict2parameters ,
132+ 'config2dict' : config2dict ,
101133 }
Original file line number Diff line number Diff line change 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+ register : _scontrol_config
6+
7+ - name : Create facts directory
8+ ansible.builtin.file :
9+ path : /etc/ansible/facts.d/
10+ state : directory
11+ owner : root
12+ group : root
13+ mode : ugo=rwX
14+
15+ - name : Template slurm configuration facts
16+ copy :
17+ dest : /etc/ansible/facts.d/slurm.fact
18+ content : " {{ _scontrol_config.stdout_lines | config2dict | to_nice_json }}"
19+ owner : slurm
20+ group : slurm
21+ mode : ug=rw,o=r # any user can run scontrol show config anyway
22+ register : _template_facts
23+
24+ - name : Reload facts if necessary
25+ ansible.builtin.setup :
26+ filter : ansible_local
27+ when : _template_facts.changed
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments