Skip to content

Commit

Permalink
Merge pull request #243 from stackhpc/feature/auto-ood-host-regex
Browse files Browse the repository at this point in the history
Automatically generate openondemand_host_regex
  • Loading branch information
sjpb authored Dec 21, 2022
2 parents 0856624 + 24a23f7 commit 230ff80
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
17 changes: 16 additions & 1 deletion ansible/filter_plugins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jinja2
from ansible.module_utils.six import string_types
import os.path
import re

def prometheus_node_exporter_targets(hosts, env):
result = []
Expand All @@ -34,6 +35,19 @@ def readfile(fpath):
def exists(fpath):
return os.path.isfile(fpath)

def to_ood_regex(items):
""" Convert a list of strings possibly containing digits into a regex containing \d+
eg {{ [compute-001, compute-002, control] | to_regex }} -> '(compute-\d+)|(control)'
"""

# There's a python bug which means re.sub() can't use '\d' in the replacement so
# have to do replacement in two stages:
r = [re.sub(r"\d+", 'XBACKSLASHX', v) for v in items]
r = [v.replace('XBACKSLASHX', '\d+') for v in set(r)]
r = ['(%s)' % v for v in r]
return '|'.join(r)

class FilterModule(object):
''' Ansible core jinja2 filters '''

Expand All @@ -47,5 +61,6 @@ def filters(self):
'readfile': readfile,
'prometheus_node_exporter_targets': prometheus_node_exporter_targets,
'exists': exists,
'warn': self.warn
'warn': self.warn,
'to_ood_regex': to_ood_regex,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
openondemand_auth: basic_pam
openondemand_host_regex: '({{ openhpc_cluster_name }}-compute-\d+)|({{ groups["grafana"] | first }})' # allows proxying to compute nodes for apps and control for monitoring
openondemand_jupyter_partition: small
openondemand_desktop_partition: small
#openondemand_dashboard_support_url:
Expand Down
6 changes: 6 additions & 0 deletions environments/common/inventory/group_vars/all/openondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

# openondemand_servername: '' # Must be defined when using openondemand

# Regex defining hosts which openondemand can proxy; the default regex is compute nodes (for apps) and grafana host,
# e.g. if the group `compute` has hosts `compute-{0,1,2,..}` this will be '(compute-\d+)|(control)'.
# The autogenerated regex may need overriding if compute node names do not contain numbers in a consistent position
# or include regex special characters.
openondemand_host_regex: "{{ (groups['compute'] + groups['grafana']) | to_ood_regex }}"

ondemand_package: ondemand-2.0.29

openondemand_dashboard_links: # TODO: should really only be deployed if grafana is deployed and proxying configured
Expand Down

0 comments on commit 230ff80

Please sign in to comment.