From ac2e053886332916d42c47081078f76eca3e4cf5 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 18 Apr 2025 20:14:50 +0200 Subject: [PATCH] Allow vhosts to be defined without DocumentRoot Horizon at the moment does not have DocumentRoot defined as this is configured via Alias instead. Change-Id: Iae886d3bceb61247039fdb26ce0844f08934f8b6 --- tasks/httpd_pre_install.yml | 2 +- tasks/main.yml | 3 +-- templates/httpd_vhost.conf.j2 | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tasks/httpd_pre_install.yml b/tasks/httpd_pre_install.yml index fc7fd0b..3e34711 100644 --- a/tasks/httpd_pre_install.yml +++ b/tasks/httpd_pre_install.yml @@ -36,7 +36,7 @@ ( httpd_vhosts | selectattr('state', 'defined') | selectattr('state', 'eq', 'present') + httpd_vhosts | selectattr('state', 'undefined') - ) | map(attribute='document_root') | map('community.general.dict_kv', 'path') + ) | selectattr('document_root', 'defined') | map(attribute='document_root') | map('community.general.dict_kv', 'path') }} _default_paths: - path: "{{ httpd_conf_dir }}/sites-available" diff --git a/tasks/main.yml b/tasks/main.yml index 5f59b58..f4155e9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,11 +18,10 @@ that: - httpd_vhosts | length > 0 - httpd_vhosts | selectattr('name', 'undefined') | length == 0 - - httpd_vhosts | selectattr('document_root', 'undefined') | length == 0 success_msg: vhosts are defined properly fail_msg: >- At least one vhost must be defined in `httpd_vhosts`. - Each vhost must contain at least `name` and `document_root` keys. + Each vhost must contain at least `name` key. - name: Gather variables for each operating system ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" diff --git a/templates/httpd_vhost.conf.j2 b/templates/httpd_vhost.conf.j2 index b0d6cd2..145ec4e 100644 --- a/templates/httpd_vhost.conf.j2 +++ b/templates/httpd_vhost.conf.j2 @@ -8,7 +8,10 @@ Listen {{ vhost['address'] | default('*') }}:{{ vhost['port'] | default(80) }} LogLevel {{ vhost['log_level'] | default(httpd_log_level) }} ErrorLog syslog:daemon CustomLog "|/usr/bin/env logger -p daemon.info -t {{ httpd_system_service_name }}:{{ vhost['name'] }}" {{ vhost['log_format'] | default(httpd_custom_log_format) }} + + {% if 'document_root' in vhost %} DocumentRoot {{ vhost['document_root'] }} + {% endif %} {% for header in vhost['headers'] | default([]) %} {{ header }}