mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-02-22 04:29:38 +01:00
Added configuration_filters
This commit is contained in:
parent
7377aa9c20
commit
0c7af2ce89
20
filter_plugins/configuration_filters.py
Normal file
20
filter_plugins/configuration_filters.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
def get_oauth2_enabled(applications, application_id):
|
||||||
|
# Retrieve the application dictionary based on the ID
|
||||||
|
app = applications.get(application_id, {})
|
||||||
|
# Retrieve the value for oauth2_proxy.enabled, default is False
|
||||||
|
enabled = app.get('oauth2_proxy', {}).get('enabled', False)
|
||||||
|
return bool(enabled)
|
||||||
|
|
||||||
|
def get_css_enabled(applications, application_id):
|
||||||
|
# Retrieve the application dictionary based on the given application_id.
|
||||||
|
app = applications.get(application_id, {})
|
||||||
|
# Retrieve the 'enabled' value from the css key, defaulting to True if not present.
|
||||||
|
enabled = app.get('css', {}).get('enabled', True)
|
||||||
|
return bool(enabled)
|
||||||
|
|
||||||
|
class FilterModule(object):
|
||||||
|
def filters(self):
|
||||||
|
return {
|
||||||
|
'get_css_enabled': get_css_enabled,
|
||||||
|
'get_oauth2_enabled': get_oauth2_enabled
|
||||||
|
}
|
@ -213,4 +213,15 @@ defaults_applications:
|
|||||||
enabled: true
|
enabled: true
|
||||||
application: "application"
|
application: "application"
|
||||||
port: "80"
|
port: "80"
|
||||||
location: "/admin/" # Protects the admin arear
|
location: "/admin/" # Protects the admin area
|
||||||
|
|
||||||
|
|
||||||
|
wordpress:
|
||||||
|
# Deactivate Global theming for wordpress role
|
||||||
|
# due to the reason that wordpress has to much different themes
|
||||||
|
# and one styling for all is not possible.
|
||||||
|
#
|
||||||
|
# May a solution could be to generate a template or css file dedicated
|
||||||
|
# for wordpress based on the theming values and import it.
|
||||||
|
css:
|
||||||
|
enabled: false
|
@ -15,10 +15,4 @@ global_theming:
|
|||||||
info: "#F0F8FF"
|
info: "#F0F8FF"
|
||||||
filters:
|
filters:
|
||||||
saturation_change: 70
|
saturation_change: 70
|
||||||
hue_shift: 0
|
hue_shift: 0
|
||||||
|
|
||||||
# Global Theming is default enabled for all roles
|
|
||||||
# If you want to disable the global css for a role, set
|
|
||||||
# global_theming_enabled: false
|
|
||||||
# in var/main.yml
|
|
||||||
global_theming_enabled: true
|
|
@ -836,7 +836,7 @@
|
|||||||
"redirectUris": [
|
"redirectUris": [
|
||||||
{%- set redirect_uris = [] -%}
|
{%- set redirect_uris = [] -%}
|
||||||
{%- for application, domain in defaults_domains.items() -%}
|
{%- for application, domain in defaults_domains.items() -%}
|
||||||
{%- if applications[application_id] is defined and applications[application_id].oauth2_proxy.enabled | default(false) | bool -%}
|
{%- if applications[application_id] is defined and applications | get_oauth2_enabled(application_id) -%}
|
||||||
{%- if domain is string -%}
|
{%- if domain is string -%}
|
||||||
{%- set _ = redirect_uris.append("https://" ~ domain ~ "/*") -%}
|
{%- set _ = redirect_uris.append("https://" ~ domain ~ "/*") -%}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% if applications[application_id].oauth2_proxy.enabled | default(false) | bool %}
|
{% if applications | get_oauth2_enabled(application_id) %}
|
||||||
oauth2-proxy:
|
oauth2-proxy:
|
||||||
image: quay.io/oauth2-proxy/oauth2-proxy:{{applications.oauth2_proxy.version}}
|
image: quay.io/oauth2-proxy/oauth2-proxy:{{applications.oauth2_proxy.version}}
|
||||||
restart: {{docker_restart_policy}}
|
restart: {{docker_restart_policy}}
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
application_id: "portfolio"
|
application_id: "portfolio"
|
||||||
repository_address: "https://github.com/kevinveenbirkenbach/portfolio"
|
repository_address: "https://github.com/kevinveenbirkenbach/portfolio"
|
||||||
global_theming_enabled: true # Activate Global CSS for Portfolio
|
|
@ -2,12 +2,4 @@ application_id: "wordpress"
|
|||||||
wordpress_max_upload_size: "64M"
|
wordpress_max_upload_size: "64M"
|
||||||
database_type: "mariadb"
|
database_type: "mariadb"
|
||||||
database_password: "{{wordpress_database_password}}"
|
database_password: "{{wordpress_database_password}}"
|
||||||
custom_wordpress_image: "custom_wordpress"
|
custom_wordpress_image: "custom_wordpress"
|
||||||
|
|
||||||
# Deactivate Global theming for wordpress role
|
|
||||||
# due to the reason that wordpress has to much different themes
|
|
||||||
# and one styling for all is not possible.
|
|
||||||
#
|
|
||||||
# May a solution could be to generate a template or css file dedicated
|
|
||||||
# for wordpress based on the theming values and import it.
|
|
||||||
global_theming_enabled: false
|
|
@ -2,7 +2,7 @@ server
|
|||||||
{
|
{
|
||||||
server_name {{domain}};
|
server_name {{domain}};
|
||||||
|
|
||||||
{% if applications[application_id].oauth2_proxy.enabled | default(false) | bool %}
|
{% if applications | get_oauth2_enabled(application_id) %}
|
||||||
{% include 'roles/docker-oauth2-proxy/templates/endpoint.conf.j2'%}
|
{% include 'roles/docker-oauth2-proxy/templates/endpoint.conf.j2'%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ server
|
|||||||
|
|
||||||
{% include 'roles/letsencrypt/templates/ssl_header.j2' %}
|
{% include 'roles/letsencrypt/templates/ssl_header.j2' %}
|
||||||
|
|
||||||
{% if applications[application_id].oauth2_proxy.enabled | default(false) %}
|
{% if applications | get_oauth2_enabled(application_id) %}
|
||||||
{% if applications[application_id].oauth2_proxy.location is defined %}
|
{% if applications[application_id].oauth2_proxy.location is defined %}
|
||||||
{# Exposed and Unprotected Location #}
|
{# Exposed and Unprotected Location #}
|
||||||
{% include 'proxy_pass.conf.j2' %}
|
{% include 'proxy_pass.conf.j2' %}
|
||||||
|
@ -22,4 +22,4 @@
|
|||||||
- name: "include the docker-oauth2-proxy role {{domain}}"
|
- name: "include the docker-oauth2-proxy role {{domain}}"
|
||||||
include_role:
|
include_role:
|
||||||
name: docker-oauth2-proxy
|
name: docker-oauth2-proxy
|
||||||
when: applications[application_id].oauth2_proxy.enabled | default(false) | bool
|
when: applications | get_oauth2_enabled(application_id)
|
@ -7,10 +7,10 @@ This role enhances your Nginx configuration by conditionally injecting global Ma
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Global Matomo Tracking**
|
- **Global Matomo Tracking**
|
||||||
When enabled (`global_matomo_tracking_enabled` is `true`), the role includes Matomo tracking configuration and injects the corresponding tracking script into your HTML.
|
The role includes Matomo tracking configuration and injects the corresponding tracking script into your HTML.
|
||||||
|
|
||||||
- **Global Theming**
|
- **Global Theming**
|
||||||
When enabled (`global_theming_enabled` is `true`), the role injects a global CSS link for consistent theming across your site.
|
The role injects a global CSS link for consistent theming across your site.
|
||||||
|
|
||||||
- **Smart Injection**
|
- **Smart Injection**
|
||||||
Uses Nginx's `sub_filter` to insert the tracking and theming snippets right before the closing `</head>` tag of your HTML documents.
|
Uses Nginx's `sub_filter` to insert the tracking and theming snippets right before the closing `</head>` tag of your HTML documents.
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
dependencies:
|
|
||||||
- nginx-modifier-css # Just required to load once
|
|
@ -1,3 +1,8 @@
|
|||||||
|
- name: "Activate Global CSS for {{domain}}"
|
||||||
|
include_role:
|
||||||
|
name: nginx-modifier-css
|
||||||
|
when: applications | get_css_enabled(application_id)
|
||||||
|
|
||||||
- name: "Activate Global Matomo Tracking for {{domain}}"
|
- name: "Activate Global Matomo Tracking for {{domain}}"
|
||||||
include_role:
|
include_role:
|
||||||
name: nginx-modifier-matomo
|
name: nginx-modifier-matomo
|
||||||
|
@ -7,11 +7,11 @@ sub_filter_types text/html;
|
|||||||
{% include 'roles/nginx-modifier-matomo/templates/matomo-tracking.conf.j2' %}
|
{% include 'roles/nginx-modifier-matomo/templates/matomo-tracking.conf.j2' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if global_theming_enabled | bool or global_matomo_tracking_enabled | bool%}
|
{% if applications | get_css_enabled(application_id) or global_matomo_tracking_enabled | bool%}
|
||||||
sub_filter '</head>' '{% if global_matomo_tracking_enabled | bool %}{% include 'roles/nginx-modifier-matomo/templates/script.j2' %}{% endif %}{% if global_theming_enabled | bool %}{% include 'roles/nginx-modifier-css/templates/link.j2' %}{% endif %}</head>';
|
sub_filter '</head>' '{% if global_matomo_tracking_enabled | bool %}{% include 'roles/nginx-modifier-matomo/templates/script.j2' %}{% endif %}{% if applications | get_css_enabled(application_id) %}{% include 'roles/nginx-modifier-css/templates/link.j2' %}{% endif %}</head>';
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if global_theming_enabled | bool %}
|
{% if applications | get_css_enabled(application_id) %}
|
||||||
{# Include Global CSS Location #}
|
{# Include Global CSS Location #}
|
||||||
{% include 'roles/nginx-modifier-css/templates/location.conf.j2' %}
|
{% include 'roles/nginx-modifier-css/templates/location.conf.j2' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# Load this role via nginx-modifier-all for consistency
|
||||||
|
|
||||||
- name: Ensure {{nginx.directories.global}} directory exists
|
- name: Ensure {{nginx.directories.global}} directory exists
|
||||||
file:
|
file:
|
||||||
path: "{{nginx.directories.global}}"
|
path: "{{nginx.directories.global}}"
|
||||||
@ -5,7 +7,7 @@
|
|||||||
owner: "{{nginx.user}}"
|
owner: "{{nginx.user}}"
|
||||||
group: "{{nginx.user}}"
|
group: "{{nginx.user}}"
|
||||||
mode: '0755'
|
mode: '0755'
|
||||||
when: run_once_nginx_global_css is not defined and global_theming_enabled | bool
|
when: run_once_nginx_global_css is not defined
|
||||||
|
|
||||||
- name: Deploy global.css from template
|
- name: Deploy global.css from template
|
||||||
template:
|
template:
|
||||||
@ -14,18 +16,18 @@
|
|||||||
owner: "{{nginx.user}}"
|
owner: "{{nginx.user}}"
|
||||||
group: "{{nginx.user}}"
|
group: "{{nginx.user}}"
|
||||||
mode: '0644'
|
mode: '0644'
|
||||||
when: run_once_nginx_global_css is not defined and global_theming_enabled | bool
|
when: run_once_nginx_global_css is not defined
|
||||||
|
|
||||||
- name: Get stat for global.css destination file
|
- name: Get stat for global.css destination file
|
||||||
stat:
|
stat:
|
||||||
path: "{{ global_css_destination }}"
|
path: "{{ global_css_destination }}"
|
||||||
register: global_css_stat
|
register: global_css_stat
|
||||||
when: run_once_nginx_global_css is not defined and global_theming_enabled | bool
|
when: run_once_nginx_global_css is not defined
|
||||||
|
|
||||||
- name: Set global_css_version to file modification time
|
- name: Set global_css_version to file modification time
|
||||||
set_fact:
|
set_fact:
|
||||||
global_css_version: "{{ global_css_stat.stat.mtime }}"
|
global_css_version: "{{ global_css_stat.stat.mtime }}"
|
||||||
when: run_once_nginx_global_css is not defined and global_theming_enabled | bool
|
when: run_once_nginx_global_css is not defined
|
||||||
|
|
||||||
- name: Mark global css tasks as run once
|
- name: Mark global css tasks as run once
|
||||||
set_fact:
|
set_fact:
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# Load this role via nginx-modifier-all for consistency
|
||||||
|
|
||||||
- name: "Relevant variables for role: {{ role_path | basename }}"
|
- name: "Relevant variables for role: {{ role_path | basename }}"
|
||||||
debug:
|
debug:
|
||||||
msg:
|
msg:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
- name: "Merge detached_files with applications.oauth2_proxy.configuration_file"
|
- name: "Merge detached_files with applications.oauth2_proxy.configuration_file"
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
merged_detached_files: "{{ detached_files + [applications.oauth2_proxy.configuration_file] }}"
|
merged_detached_files: "{{ detached_files + [applications.oauth2_proxy.configuration_file] }}"
|
||||||
when: applications[application_id].oauth2_proxy.enabled | default(false) | bool
|
when: applications | get_oauth2_enabled(application_id)
|
||||||
|
|
||||||
- name: "backup detached files"
|
- name: "backup detached files"
|
||||||
command: >
|
command: >
|
||||||
|
Loading…
x
Reference in New Issue
Block a user