Skip to content

Commit

Permalink
Merge pull request #498 from diedpigs/feat-variable-backend-server
Browse files Browse the repository at this point in the history
Use variables for http proxy backend hosts
  • Loading branch information
diedpigs authored Nov 27, 2024
2 parents 3a550e4 + 964362c commit cb7c1e2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
3 changes: 3 additions & 0 deletions group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 24 additions & 11 deletions roles/http_proxy/files/rewrite_map.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions roles/http_proxy/files/rewritemap_config.py

This file was deleted.

6 changes: 3 additions & 3 deletions roles/http_proxy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions roles/http_proxy/templates/rewrite_map_config_py.j2
Original file line number Diff line number Diff line change
@@ -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 %}

0 comments on commit cb7c1e2

Please sign in to comment.