diff --git a/group_vars/all b/group_vars/all index 9b71b687..522cd850 100644 --- a/group_vars/all +++ b/group_vars/all @@ -354,6 +354,9 @@ # http_proxy enable_http_proxy: false + target_groups: + - {"name": "gpfs4", "host": "login001", "default": True} + - {"name": "gpfs5", "host": "login002", "default": False} # cod_slurm frozen_file_list: diff --git a/roles/http_proxy/files/rewrite_map.py b/roles/http_proxy/files/rewrite_map.py index ed6bb0b5..4e6a966c 100644 --- a/roles/http_proxy/files/rewrite_map.py +++ b/roles/http_proxy/files/rewrite_map.py @@ -1,19 +1,32 @@ #!/usr/bin/env python3 import grp import sys -import rewritemap_config as cfg +import rewrite_map_config as cfg while sys.stdin: + hostname = "" try: username = sys.stdin.readline().strip() ## It is very important to use strip! - if cfg.DEBUG: print(username) - if not username: - print(cfg.default_hostname) - if username in grp.getgrnam(cfg.target_grp).gr_mem: - print(cfg.target_hostname) - else: - print(cfg.default_hostname) - sys.stdout.flush() + if cfg.DEBUG: + print("username: ", username) + + if username: + for group in cfg.target_groups: + if cfg.DEBUG: + print("Checking group: ", group) + print("\t", grp.getgrnam(group).gr_mem) + + if username in grp.getgrnam(group).gr_mem: + hostname = cfg.target_groups[group] + break + + if not hostname: + hostname = cfg.default_hostname + except: - print(cfg.default_hostname) - sys.stdout.flush() + hostname = cfg.default_hostname + + print(hostname) + sys.stdout.flush() + if cfg.DEBUG: + break diff --git a/roles/http_proxy/files/rewritemap_config.py b/roles/http_proxy/files/rewritemap_config.py deleted file mode 100644 index d21f2651..00000000 --- a/roles/http_proxy/files/rewritemap_config.py +++ /dev/null @@ -1,5 +0,0 @@ -DEBUG = False -target_grp = 'gpfs5' -target_hostname = 'login002.cm.cluster' - -default_hostname = 'login001.cm.cluster' diff --git a/roles/http_proxy/tasks/main.yml b/roles/http_proxy/tasks/main.yml index c986b890..6eec5b6d 100644 --- a/roles/http_proxy/tasks/main.yml +++ b/roles/http_proxy/tasks/main.yml @@ -109,10 +109,10 @@ dest: /etc/httpd/conf.d/front-end.conf - name: Add apache rewritemap script config - ansible.builtin.copy: - src: rewritemap_config.py + ansible.builtin.template: + src: rewrite_map_config_py.j2 mode: '755' - dest: /var/www/rewritemap_config.py + dest: /var/www/rewrite_map_config.py - name: Add apache rewritemap script ansible.builtin.copy: diff --git a/roles/http_proxy/templates/rewrite_map_config_py.j2 b/roles/http_proxy/templates/rewrite_map_config_py.j2 new file mode 100644 index 00000000..3d247e70 --- /dev/null +++ b/roles/http_proxy/templates/rewrite_map_config_py.j2 @@ -0,0 +1,11 @@ +DEBUG = False +target_groups = { + {% for group in target_groups %} + "{{ group.name }}": "{{ group.host }}", + {% endfor %} +} +{% for group in target_groups %} +{% if group.default %} +default_hostname = "{{ group.host }}" +{% endif %} +{% endfor %}