Skip to content

Commit c8f231b

Browse files
authored
Merge pull request #234 from ksuderman/231-themes-config
Fix themes_config_file_by_host to always contain a dict
2 parents ab6b8f6 + b1dd2e6 commit c8f231b

File tree

3 files changed

+224
-59
lines changed

3 files changed

+224
-59
lines changed

defaults/main.yml

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ galaxy_manage_gravity: "{{ false if __galaxy_major_version is version('22.05', '
2323
galaxy_manage_systemd: no # For Galaxy
2424
galaxy_manage_systemd_reports: no # For Reports
2525
galaxy_manage_cleanup: no
26-
galaxy_manage_themes: "{{ galaxy_manage_static_setup and (galaxy_themes is defined or galaxy_themes_subdomains) }}"
26+
galaxy_manage_themes: "{{ galaxy_manage_static_setup and (galaxy_themes is defined or galaxy_themes_subdomains | length > 0) }}"
2727
galaxy_manage_subdomain_static: no
2828
galaxy_manage_host_filters: no
2929
galaxy_auto_brand: no # automatically sets the subdomain name as brand
@@ -302,64 +302,15 @@ galaxy_app_config_default:
302302

303303
# Static and themes configuration, will only be added if galaxy_manage_themes
304304
static_enabled: "{{ galaxy_manage_subdomain_static }}"
305-
static_dir_by_host: >
306-
{ {% if galaxy_manage_subdomain_static %}
307-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}/',
308-
{% for subdomain in galaxy_themes_subdomains %}
309-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/',
310-
{% endfor %}
311-
{% endif %} }
312-
static_images_dir_by_host: >
313-
{ {% if galaxy_manage_subdomain_static %}
314-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}/images',
315-
{% for subdomain in galaxy_themes_subdomains %}
316-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/images',
317-
{% endfor %}
318-
{% endif %} }
319-
static_welcome_html_by_host: >
320-
{ {% if galaxy_manage_subdomain_static %}
321-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}/welcome.html',
322-
{% for subdomain in galaxy_themes_subdomains %}
323-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/welcome.html',
324-
{% endfor %}
325-
{% endif %} }
326-
static_scripts_dir_by_host: >
327-
{ {% if galaxy_manage_subdomain_static %}
328-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}/scripts',
329-
{% for subdomain in galaxy_themes_subdomains %}
330-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/scripts',
331-
{% endfor %}
332-
{% endif %} }
333-
static_favicon_dir_by_host: >
334-
{ {% if galaxy_manage_subdomain_static %}
335-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}',
336-
{% for subdomain in galaxy_themes_subdomains %}
337-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}',
338-
{% endfor %}
339-
{% endif %} }
340-
static_robots_txt_by_host: >
341-
{ {% if galaxy_manage_subdomain_static %}
342-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_static_dir }}',
343-
{% for subdomain in galaxy_themes_subdomains %}
344-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}',
345-
{% endfor %}
346-
{% endif %} }
347-
themes_config_file_by_host: >
348-
{ {% if galaxy_manage_themes and galaxy_themes_subdomains %}
349-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_config.galaxy.themes_config_file | default((galaxy_config_dir, "themes_conf.yml") | path_join) }}',
350-
{% for subdomain in galaxy_themes_subdomains %}
351-
{% if subdomain.theme is defined %}
352-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': 'themes_conf-{{ subdomain.name }}.yml',
353-
{% endif %}
354-
{% endfor %}
355-
{% endif %} }
356-
brand_by_host: >
357-
{ {% if galaxy_auto_brand %}
358-
'{{ galaxy_themes_instance_domain }}': '{{ galaxy_themes_instance_domain }}',
359-
{% for subdomain in galaxy_themes_subdomains %}
360-
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ subdomain.name[0]|upper }}{{ subdomain.name[1:] }}',
361-
{% endfor %}
362-
{% endif %} }
305+
# The following *_by_host dicts are built at runtime in tasks/config-facts.yml
306+
static_dir_by_host: {}
307+
static_images_dir_by_host: {}
308+
static_welcome_html_by_host: {}
309+
static_scripts_dir_by_host: {}
310+
static_favicon_dir_by_host: {}
311+
static_robots_txt_by_host: {}
312+
themes_config_file_by_host: {}
313+
brand_by_host: {}
363314
# Need to set galaxy_config_default[galaxy_app_config_section] dynamically but Ansible/Jinja2 does not make this easy
364315
galaxy_config_default: "{{ {} | combine({galaxy_app_config_section: galaxy_app_config_default}) }}"
365316
galaxy_config_merged: "{{ galaxy_config_default | combine(galaxy_config | default({}), recursive=True) }}"

tasks/config-facts.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
# Build proper dict variables for *_by_host configuration to avoid string literals
3+
# This fixes the bug where these variables would evaluate to malformed strings
4+
# like '{ }\n\n ' instead of empty dicts when conditions are false
5+
6+
- name: Build static_dir_by_host dict
7+
set_fact:
8+
_galaxy_static_dir_by_host_dict: >-
9+
{{
10+
_galaxy_static_dir_by_host_dict | default({}) |
11+
combine({
12+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name ~ '/')
13+
})
14+
}}
15+
loop: "{{ galaxy_themes_subdomains }}"
16+
loop_control:
17+
loop_var: subdomain
18+
when: galaxy_manage_subdomain_static
19+
20+
- name: Add base domain to static_dir_by_host dict
21+
set_fact:
22+
_galaxy_static_dir_by_host_dict: >-
23+
{{
24+
_galaxy_static_dir_by_host_dict | default({}) |
25+
combine({galaxy_themes_instance_domain: (galaxy_static_dir ~ '/')})
26+
}}
27+
when: galaxy_manage_subdomain_static
28+
29+
- name: Build static_images_dir_by_host dict
30+
set_fact:
31+
_galaxy_static_images_dir_by_host_dict: >-
32+
{{
33+
_galaxy_static_images_dir_by_host_dict | default({}) |
34+
combine({
35+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name ~ '/images')
36+
})
37+
}}
38+
loop: "{{ galaxy_themes_subdomains }}"
39+
loop_control:
40+
loop_var: subdomain
41+
when: galaxy_manage_subdomain_static
42+
43+
- name: Add base domain to static_images_dir_by_host dict
44+
set_fact:
45+
_galaxy_static_images_dir_by_host_dict: >-
46+
{{
47+
_galaxy_static_images_dir_by_host_dict | default({}) |
48+
combine({galaxy_themes_instance_domain: (galaxy_static_dir ~ '/images')})
49+
}}
50+
when: galaxy_manage_subdomain_static
51+
52+
- name: Build static_welcome_html_by_host dict
53+
set_fact:
54+
_galaxy_static_welcome_html_by_host_dict: >-
55+
{{
56+
_galaxy_static_welcome_html_by_host_dict | default({}) |
57+
combine({
58+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name ~ '/welcome.html')
59+
})
60+
}}
61+
loop: "{{ galaxy_themes_subdomains }}"
62+
loop_control:
63+
loop_var: subdomain
64+
when: galaxy_manage_subdomain_static
65+
66+
- name: Add base domain to static_welcome_html_by_host dict
67+
set_fact:
68+
_galaxy_static_welcome_html_by_host_dict: >-
69+
{{
70+
_galaxy_static_welcome_html_by_host_dict | default({}) |
71+
combine({galaxy_themes_instance_domain: (galaxy_static_dir ~ '/welcome.html')})
72+
}}
73+
when: galaxy_manage_subdomain_static
74+
75+
- name: Build static_scripts_dir_by_host dict
76+
set_fact:
77+
_galaxy_static_scripts_dir_by_host_dict: >-
78+
{{
79+
_galaxy_static_scripts_dir_by_host_dict | default({}) |
80+
combine({
81+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name ~ '/scripts')
82+
})
83+
}}
84+
loop: "{{ galaxy_themes_subdomains }}"
85+
loop_control:
86+
loop_var: subdomain
87+
when: galaxy_manage_subdomain_static
88+
89+
- name: Add base domain to static_scripts_dir_by_host dict
90+
set_fact:
91+
_galaxy_static_scripts_dir_by_host_dict: >-
92+
{{
93+
_galaxy_static_scripts_dir_by_host_dict | default({}) |
94+
combine({galaxy_themes_instance_domain: (galaxy_static_dir ~ '/scripts')})
95+
}}
96+
when: galaxy_manage_subdomain_static
97+
98+
- name: Build static_favicon_dir_by_host dict
99+
set_fact:
100+
_galaxy_static_favicon_dir_by_host_dict: >-
101+
{{
102+
_galaxy_static_favicon_dir_by_host_dict | default({}) |
103+
combine({
104+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name)
105+
})
106+
}}
107+
loop: "{{ galaxy_themes_subdomains }}"
108+
loop_control:
109+
loop_var: subdomain
110+
when: galaxy_manage_subdomain_static
111+
112+
- name: Add base domain to static_favicon_dir_by_host dict
113+
set_fact:
114+
_galaxy_static_favicon_dir_by_host_dict: >-
115+
{{
116+
_galaxy_static_favicon_dir_by_host_dict | default({}) |
117+
combine({galaxy_themes_instance_domain: galaxy_static_dir})
118+
}}
119+
when: galaxy_manage_subdomain_static
120+
121+
- name: Build static_robots_txt_by_host dict
122+
set_fact:
123+
_galaxy_static_robots_txt_by_host_dict: >-
124+
{{
125+
_galaxy_static_robots_txt_by_host_dict | default({}) |
126+
combine({
127+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (galaxy_themes_static_path ~ '/static-' ~ subdomain.name)
128+
})
129+
}}
130+
loop: "{{ galaxy_themes_subdomains }}"
131+
loop_control:
132+
loop_var: subdomain
133+
when: galaxy_manage_subdomain_static
134+
135+
- name: Add base domain to static_robots_txt_by_host dict
136+
set_fact:
137+
_galaxy_static_robots_txt_by_host_dict: >-
138+
{{
139+
_galaxy_static_robots_txt_by_host_dict | default({}) |
140+
combine({galaxy_themes_instance_domain: galaxy_static_dir})
141+
}}
142+
when: galaxy_manage_subdomain_static
143+
144+
- name: Build themes_config_file_by_host dict for subdomains
145+
set_fact:
146+
_galaxy_themes_config_file_by_host_dict: >-
147+
{{
148+
_galaxy_themes_config_file_by_host_dict | default({}) |
149+
combine({
150+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): ('themes_conf-' ~ subdomain.name ~ '.yml')
151+
})
152+
}}
153+
loop: "{{ galaxy_themes_subdomains }}"
154+
loop_control:
155+
loop_var: subdomain
156+
when:
157+
- galaxy_manage_themes
158+
- galaxy_themes_subdomains | length > 0
159+
- subdomain.theme is defined
160+
161+
- name: Add base domain to themes_config_file_by_host dict
162+
set_fact:
163+
_galaxy_themes_config_file_by_host_dict: >-
164+
{{
165+
_galaxy_themes_config_file_by_host_dict | default({}) |
166+
combine({galaxy_themes_instance_domain: (galaxy_config.galaxy.themes_config_file | default((galaxy_config_dir, 'themes_conf.yml') | path_join))})
167+
}}
168+
when:
169+
- galaxy_manage_themes
170+
- galaxy_themes_subdomains | length > 0
171+
172+
- name: Build brand_by_host dict
173+
set_fact:
174+
_galaxy_brand_by_host_dict: >-
175+
{{
176+
_galaxy_brand_by_host_dict | default({}) |
177+
combine({
178+
(subdomain.name ~ '.' ~ galaxy_themes_instance_domain): (subdomain.name[0]|upper ~ subdomain.name[1:])
179+
})
180+
}}
181+
loop: "{{ galaxy_themes_subdomains }}"
182+
loop_control:
183+
loop_var: subdomain
184+
when: galaxy_auto_brand
185+
186+
- name: Add base domain to brand_by_host dict
187+
set_fact:
188+
_galaxy_brand_by_host_dict: >-
189+
{{
190+
_galaxy_brand_by_host_dict | default({}) |
191+
combine({galaxy_themes_instance_domain: galaxy_themes_instance_domain})
192+
}}
193+
when: galaxy_auto_brand
194+
195+
- name: Override galaxy_app_config_default with proper dict values
196+
set_fact:
197+
galaxy_app_config_default: >-
198+
{{
199+
galaxy_app_config_default |
200+
combine({
201+
'static_dir_by_host': _galaxy_static_dir_by_host_dict | default({}),
202+
'static_images_dir_by_host': _galaxy_static_images_dir_by_host_dict | default({}),
203+
'static_welcome_html_by_host': _galaxy_static_welcome_html_by_host_dict | default({}),
204+
'static_scripts_dir_by_host': _galaxy_static_scripts_dir_by_host_dict | default({}),
205+
'static_favicon_dir_by_host': _galaxy_static_favicon_dir_by_host_dict | default({}),
206+
'static_robots_txt_by_host': _galaxy_static_robots_txt_by_host_dict | default({}),
207+
'themes_config_file_by_host': _galaxy_themes_config_file_by_host_dict | default({}),
208+
'brand_by_host': _galaxy_brand_by_host_dict | default({})
209+
})
210+
}}

tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import_tasks: layout.yml
2727
tags: always
2828

29+
- name: Build config facts for *_by_host variables
30+
import_tasks: config-facts.yml
31+
tags: always
32+
2933
- name: Include user creation tasks
3034
include_tasks:
3135
file: user.yml

0 commit comments

Comments
 (0)